A, post request distortion
<filter>
<filter-name>CharacterEncodingFilter</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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- More garbage problem can be solved post request.
Two, get garbled request
- There are two parameters to get the request Chinese garbled solution to occur:
- Modifying tomcat configuration file to add the same coding and engineering codes, as follows:
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
- Another method of re-encoding the parameters:
String userName new
String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")
- ISO8859-1 is tomcat default encoding, content needs to be encoded by the tomcat utf-8 encoding