<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    紀念SUN

    Powered By Andy

    URL編碼

    package cn.struts.util;

    import java.util.Arrays;

    /**
     * 字符編碼
     */
    public class URLEnCodeing {

        private static final char[] c = { '\\', '/', ':', '?', '&'};

        /**
         * URL 編碼 http://localhost:8080/webproject/中國測試
         *
         * @param url http://localhost:8080/webproject/%4e2d%56fd%6d4b%8bd5
         *
         * @return
         */
        public static String escape(String url) {
     int length = url.length();
     StringBuilder sb = new StringBuilder(length);
     char currentChar;
     for (int i = 0; i < length; i++) {
         // 當前字符是不是數字,或字母,特殊字符'\\', '/', ':'
         currentChar = url.charAt(i);
         if(currentChar == 37)
      throw new RuntimeException("不能是%");
         if (currentChar <= 127) {
      sb.append(currentChar);
         } else {
      sb.append("%");
      sb.append(Integer.toString(currentChar, 16));
         }
     }

     return sb.toString();
        }

        /**
         * URL 編碼 http://localhost:8080/webproject/中國測試
         *
         * @param url http://localhost:8080/webproject/%4e2d%56fd%6d4b%8bd5?time=11234566&name=%4e16%754c
         *
         * @return
         */
        public static String unEscape(String url) {
     int length = url.length();
     StringBuilder sb = new StringBuilder(length);
     String[] str = url.split("%");
     sb.append(str[0]);
     // %4e2d //"8bd5?time=11234566&name="
     for (int i = 1; i < str.length; i++) {
         String s = str[i];
         if(s.length() > 4){
      sb.append((char)Integer.parseInt(s.substring(0, 4), 16));
      sb.append(s.substring(4));
         }else
         sb.append((char) Integer.parseInt(str[i], 16));
     }
     return sb.toString();
        }

        public static void main(String[] args) {
     String value = "http://localhost:8080/webpr&oject/中國測試?time=11234566&name=世界";
     String url = "http://localhost:8080/webp25r&oject/%4e2d%56fd%6d4b%8bd5?time=11234566&name=%4e16%754c";
     System.out.println(URLEnCodeing.escape(value));
     System.out.println(URLEnCodeing.unEscape(url));
     System.out.println(Integer.toString((char)'%',16));
     

        }

    }

    posted on 2010-02-22 18:57 Powered By Andy 閱讀(2009) 評論(0)  編輯  收藏


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


    網站導航:
     

    導航

    <2010年2月>
    31123456
    78910111213
    14151617181920
    21222324252627
    28123456
    78910111213

    統計

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产精品1024在线永久免费 | 男人天堂免费视频| **俄罗斯毛片免费| 亚洲AV无码一区二区二三区入口| 国产伦精品一区二区免费| 亚洲中文字幕无码不卡电影| 亚洲国产精品一区第二页| 亚洲国产成+人+综合| 亚洲高清有码中文字| 国产又黄又爽又大的免费视频| 77777亚洲午夜久久多人| 在线免费观看h片| 亚洲国产精品久久久久网站| 最近高清中文字幕免费| 亚洲人成网站在线观看青青| 亚洲精品视频久久| 国产精品成人亚洲| **毛片免费观看久久精品| 亚洲美女视频网站| 无码中文在线二区免费| 国产亚洲综合成人91精品| 日本在线免费播放| 久久乐国产综合亚洲精品| 免费一级黄色毛片| 成人A片产无码免费视频在线观看| 日韩中文无码有码免费视频 | 亚洲看片无码在线视频| 国产特级淫片免费看| 亚洲ts人妖网站| 国产成人免费a在线视频色戒| xxxx日本在线播放免费不卡| 免费理论片51人人看电影| 人妖系列免费网站观看| 亚洲视频一区二区| 四虎国产成人永久精品免费| 亚洲综合激情五月色一区| 亚洲人成电影网站免费| 国产亚洲男人的天堂在线观看| 亚洲国产高清人在线| 国产精品麻豆免费版| 免费无码一区二区三区|