UTF8转换

public static String encodeUrl(String source){
        String result = source;
        try{
            result = java.net.URLEncoder.encode(source,"utf-8");
        }catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return result;
    }

实际运行结果:

 public static void main(String[] args){
     String oaurl = "http://127.0.0.1/wxshop/yh/src/goodList/details?gid=26";
     System.out.println(encodeUrl(oaurl));
     //http%3A%2F%2F127.0.0.1%2Fwxshop%2Fyh%2Fsrc%2FgoodList%2Fdetails%3Fgid%3D26

 }

 

posted @ 2015-03-17 23:22  vikey.z  阅读(184)  评论(0编辑  收藏  举报