The problem of parsing the Chinese parameter of Get mode in Spring MVC controller is garbled (how Tomcat decodes)

Source: Internet
Author: User

The problem description of the Chinese parameter of the Spring MVC controller parsing get mode is garbled

In the work of using the sudden appearance from get to get the Chinese parameters garbled (the newly installed machine, Tomcat re-download and configuration), looked for a half-day finally found a solution.

Why is it garbled?

Spring MVC is based on a servlet, and the URL for get comes in before the HTTP request arrives at the servlet resolution, which is urldecode by Tomcat first. Tomcat's default URL decoding result for Get mode is iso-8859-1 instead of what I think of as UTF-8.

Solution Solutions

The solution is also simple, except for the usual transcoding filter,jsp configured in the Project Web. Xml with code files, the key point is to configure Connector urieconding= in Server.xml in Tomcat's conf directory. The "UTF-8" property can be.
Description of this attribute in the official documentation:

URIENCODING:THIS Specifies the character encoding used to decode the URI bytes, after%xx decoding the URL. If not specified, iso-8859-1 'll be used.

The reference document here is Tomcat5.5, and the pro-test works for TOMCAT7.

Note:

<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" usebodyencodingforuri= "true"/>

by usebodyencodingforuri= the "true" configuration and then setting the default request.setcharacterencoding encoding in the code, the garbled problem can be effectively resolved.

, recommended with usebodyencodingforuri= "true"

The problem of parsing the Chinese parameter of Get mode in Spring MVC controller is garbled (how Tomcat decodes)

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.