1、使用转码
/**
* 将从 request中得到的参数 解码
* @param source
* @return
* @throws UnsupportedEncodingException
*/
public static String encodeParameter(String source)
throws UnsupportedEncodingException {
source = (source == null) ? null : new String(source
.getBytes("iso-8859-1"), "utf-8");
return source;
}
ex:
String str = request.getParameter("str");
CommonUtil.encodeParameter(functionName);
2、配置tomcat(好处是设置之后,一劳永逸)
在server.xml中添加urlencroing=utf8
<Connector port="8029" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="utf-8"
redirectPort="8443" />
需要注意的是这两个配置不能同时使用,否则还会是乱码。一般在工程开发之初就把规则定好!
解决HTTP请求中文乱码

1522

被折叠的 条评论
为什么被折叠?



