Problem Description:
When you pass the SPRINGMVC parameter, when you encounter a GET request for Chinese information, the page answer displays a garbled language.
Workaround:
One, we need to Request.getparameter ("parameter name") to obtain the string first encoded into a byte stream with iso-8859-1, and then decoded it into a character stream with Utf-8, the code is as follows:
New String (request.getparameter ("parameter name"). GetBytes ("Iso-8859-1"), "Utf-8");
Second, we can also set the encoding by setting the URL encoding set (uriencoding) through the Tomcat configuration file.
In Tomcat's server.xml configuration file, add uriencoding= "UTF-8"
It is important to note that when you run the project file with Eclipse, if you change the server.xml file in the Tomcat installation directory , you will change The Server.xml file under Servers configured by Eclipse itself . Because this server is used by eclipse to run the project.
As shown in the following:
Add uriencoding= "UTF-8"
< Connector ConnectionTimeout = "20000" Port = "8080" Protocol = "http/1.1" Redirectport = "8443" />
Modified to:
<uriencoding= "UTF-8" connectiontimeout= "20000" Port = "8080" protocol= "http/1.1" redirectport= "8443"/>
Note:
The meanings of these two properties are explained below:
The Usebodyencodingforuri parameter indicates whether the data submitted by the URL and the data submitted in the form are re-encoded with the request.setcharacterencoding parameter, which is false by default.
The uriencoding parameter specifies a uniform recoding (decoding) encoding for all get mode requests.
The difference between uriencoding and Usebodyencodingforuri is that
Uriencoding is a uniform re-encoding of all requests for Get methods,
Usebodyencodingforuri is the re-encoding of the data according to the request.setcharacterencoding parameter of the page that should be requested, and different pages can have different recoding codes.
after configuring usebodyencodingforuri= "True" , you can solve the Chinese garbled problem of normal get requests, but the Chinese will still be garbled for GET requests initiated via Ajax. Please change usebodyencodingforuri= "true" to uriencoding= "UTF-8" .
When you use the SPRINGMVC parameter to pass, troubleshoot a GET request with a Chinese garbled problem