搞定URL中文编码
原先以为这样就可以
public static String StrToURL(String str) {
String result = null;
try {
result = URLEncoder.encode(str, "utf-8");// gb2312
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public static String URLtoStr(String url) {
String result = null;
try {
result = URLDecoder.decode(url, "utf-8");
// 空格替换成加号
result = result.replaceAll(" ", "+");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
没想到中文还是乱码,通过抓包发现传过来的东西没错,发现是tomcat的问题,加了下面的就可以了
<Connector port="8236" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" />