encoding settings in Web. XML in the previous project:
<filter> <filter-name>CharacterEncoding</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>characterencoding</filter-name> <url-pattern>/*</url-pattern> </ Filter-mapping>
However, this setting is for post requests, Tomacat for Get and post requests are handled differently, to handle encoding problems for GET requests, you need to change the Server.xml configuration file for Tomcat, as follows:
<connector connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443"/>
Switch
<connector connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443" useBodyEncodingForURI= " True "/>
The key point here: If you are changing the Server.xml configuration file of the Tomcat installation directory, then when you run the project with Eclipse, you will find that the configuration does not work, because Eclipse is configured in eclipse when running the project, then the problem is solved, open the EC The tomcat configuration file in Lipse can be changed to the following:
Note: After configuring Usebodyencodingforuri= "true", it is possible to solve the Chinese garbled problem of normal get requests, but the Chinese will still be garbled for GET requests initiated via Ajax, please put usebodyencodingforuri= "true" Change to Uriencoding= "UTF-8".
SPRINGMVC Learning Series-PostScript solve the problem of Chinese garbled characters in GET request