java URL 編碼解碼

來源:互聯網
上載者:User

標籤:author   java.net   ==   rgs   private   div   import   trace   轉碼   

 

 1 import java.io.UnsupportedEncodingException; 2 /** 3  * url轉碼、解碼 4  * 5  * @author lifq  6  * @date 2015-3-17 下午04:09:35 7  */ 8 public class UrlUtil { 9     private final static String ENCODE = "GBK"; 10     /**11      * URL 解碼12      *13      * @return String14      * @author lifq15      * @date 2015-3-17 下午04:09:5116      */17     public static String getURLDecoderString(String str) {18         String result = "";19         if (null == str) {20             return "";21         }22         try {23             result = java.net.URLDecoder.decode(str, ENCODE);24         } catch (UnsupportedEncodingException e) {25             e.printStackTrace();26         }27         return result;28     }29     /**30      * URL 轉碼31      *32      * @return String33      * @author lifq34      * @date 2015-3-17 下午04:10:2835      */36     public static String getURLEncoderString(String str) {37         String result = "";38         if (null == str) {39             return "";40         }41         try {42             result = java.net.URLEncoder.encode(str, ENCODE);43         } catch (UnsupportedEncodingException e) {44             e.printStackTrace();45         }46         return result;47     }48 49     /**50      * 51      * @return void52      * @author lifq53      * @date 2015-3-17 下午04:09:1654      */55     public static void main(String[] args) {56         String str = "測試1";57         System.out.println(getURLEncoderString(str));58         System.out.println(getURLDecoderString(str));59         60     }61 62 }

 

java URL 編碼解碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.