SPRINGMVC troubleshooting GET requests with Chinese garbled characters

Source: Internet
Author: User

<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:

650) this.width=650; "src=" Http://images.cnitblog.com/blog/205051/201412/222012348121043.png "style=" border:0px; margin:10px; "/>

Note : After configuring Usebodyencodingforuri= "true" , can solve the normal GET request of the Chinese garbled problem, but for Ajax-initiated GET request Chinese will still garbled, please Usebodyencodingforuri= "true" is changed to URIEncoding= "UTF-8" .


SPRINGMVC troubleshooting GET requests with Chinese garbled characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.