java url中文编码
public class Common{
public static String encode(String s) {
try {
return URLEncoder.encode(s,JspRunConfig.CHARSET);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}
public static String decode(String s) {
try {
return URLDecoder.decode(s,JspRunConfig.CHARSET);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}
}
使用时,如果不做任何处理就直接传递,中文也许没有问题(但不保证),但空格肯定会有问题,到接收页面无法识别。
解决办法1:Common.encode(sContent,"utf-8"); 然后再传递。比如url是"accept.jsp?content="+sContent;
读取时,使用
String sc = request.getParameter("content");
sc = new String(sc.getBytes("iso-8859-1"),"utf-8");
- lichangyu's blog
- 添加新评论
- 1358 次点击
上一篇:已经是第一篇 | 下一篇:删除JSP编译后的空行(主要针对wap用户)