The problem of garbled characters in development is really annoying. Let's summarize today.
1.post Way to submit data Chinese garbled processing
Post way to submit the data garbled problem is easier to solve, generally the server-side encoding to the same as the front page on the line. For example, the page JSP is Utf-8, then the background is
Request.setcharacterencoding ("UTF-8");
2.get Way Submission and link submission
Both of these methods are directly to the parameters of the URL to upload to the server, they go URI
Workaround:
(1) Modify the Tomcat configuration file Server.xml, modify the Uriencoding property in connector, which defaults to "Iso8859-1"
1 < port= "8080" protocol= "http/1.1"2 ConnectionTimeout= "20000"3 redirectport= "8443" uriencoding= ' utf-8 '/>
(2) Do not change the tomcat configuration, the parameters passed back to convert the code
String data = Request.getparameter ("paramname");
byte[] Source = data.getbytes ("iso8859-1");
data = New String (source, "UTF-8");
So the data obtained is not garbled. Of course, if uriencoding in Tomcat is changed to another encoding, the iso8859-1 will be replaced with the corresponding encoding .
The ultimate solution to the problem of interactive garbled data between foreground and server