主要是
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成都
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成都