0
点赞
收藏
分享

微信扫一扫

解决中文拼接在url后的乱码问题--gbk 在url上的编码

云岭逸人 2022-11-07 阅读 98


主要是

URLEncoder.encode(temp,"UTF-8"); 


URLDecoder.decode(temp, "UTF-8");





public static void main(String[] args) throws UnsupportedEncodingException {

// TODO Auto-generated method stub

String temp = "http://local:9080/epg/2y四川tt成都";

temp = URLEncoder.encode(temp,"UTF-8");

System.out.println(temp);

temp = URLDecoder.decode(temp, "UTF-8");

System.out.println(temp);

//下面这个是测试,如果两次编码是否会出现乱码,验证结果是不会

temp = URLDecoder.decode(temp, "UTF-8");

System.out.println(temp);


}



结果如图:

http%3A%2F%2Flocal%3A9080%2Fepg%2F2y%E5%9B%9B%E5%B7%9Dtt%E6%88%90%E9%83%BD
​​​http://local:9080/epg/2y四川tt成都 ​​​http://local:9080/epg/2y四川tt成都

举报

相关推荐

0 条评论