高華的博客

          Eclipse能在Java占得一席之地
          隨筆 - 2, 文章 - 13, 評論 - 3, 引用 - 0
          數(shù)據(jù)加載中……

          使用URLEncoder和URLDecoder

          如果URL里面要包含特殊的字符和空格,你需要對其進(jìn)行編碼,你需要編碼和解碼。下面的代碼演示了如何進(jìn)行編碼和解碼。

          ??? ??? ??? ??? import java.net.*;

          ??? ??? ??? public class URL_Encoder_Decoder{

          ??? ??? ??? public static void main(String[] args){

          ??? ??? ??? ? String sir="@sir de caractere@,nr. 1290 'paragraf 3'";
          ??? ??? ??? ? try{
          ??? ??? ??? ???? String sir_codat=URLEncoder.encode(sir,"UTF-8");
          ??? ??? ??? ???? String sir_decodat=URLDecoder.decode(sir_codat,"UTF-8");
          ??? ??? ??? ???? System.out.println(sir);
          ??? ??? ??? ???? System.out.println(sir_codat);?
          ??? ??? ??? ???? System.out.println(sir_decodat);?????
          ??? ??? ??? ???? }catch(java.io.UnsupportedEncodingException e)
          ??? ??? ??? ???????? {System.out.println("Eroare:"+e.getMessage());}???????????
          ??? ??? ??? ? }
          ??? ??? ??? }

          下面是輸出結(jié)果:
          ??? ??? ??? @sir de caractere@,nr. 1290 'paragraf 3'
          ??? ??? ??? %40sir+de+caractere%40%2Cnr.+1290+%27paragraf+3%27
          ??? ??? ??? @sir de caractere@,nr. 1290 'paragraf 3'



          posted on 2007-01-19 09:12 高華 閱讀(3299) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 宁武县| 延长县| 和田县| 邛崃市| 封开县| 阿鲁科尔沁旗| 綦江县| 军事| 大连市| 江油市| 济宁市| 柳江县| 莱阳市| 会昌县| 淳化县| 长武县| 郓城县| 长丰县| 忻城县| 金门县| 普定县| 盱眙县| 福清市| 呼和浩特市| 牙克石市| 大关县| 永靖县| 中山市| 白水县| 岢岚县| 徐汇区| 海丰县| 齐河县| 涿鹿县| 峨山| 永宁县| 万山特区| 汶川县| 弋阳县| 海门市| 峨山|