1.get请求乱码解决
服务器编码,工程编程,jsp视图编码一致,则一般不会产生get乱码。
服务器编程设置,server.xml文件中如下设置即可:
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
也可以使用 String newStr = new String(byte[] ,"编码格式");
2.post请求乱码解决
在web.xml文件配置过滤器
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>