对于请求中出现参数乱码的情况的几种解决方法:
1)修改tomcat配置文件添加编码与工程编码一致;如下:
<Connection URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
2)对参数进行重新的编码:
(ISO8859-1是tomcat默认的编码,需要将tomcat编码后的内容按utf-8编码)
String userName = new String(request.getParamter("userName").getByte("ISO8859-1"),"utf-8");
3)修改页面的编码方式 :
将jsp页面的编码方式改为utf-8
4)添加过滤器
<!-- post乱码过滤器,可使用过滤器的方法解决 -->
<filter>
<description>字符集过滤器</description>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<description>字符集编码</description>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>