1, in the GET request, the key to see your tomcat in the Server.xml "<connector port=" 8080 "protocol=" http/1.1 "Connectiontimeou t= "20000" redirectport= "8443"/> "This connector is configured uriencoding value, do not configure the default is Iso8859-1, if written like Utf-8, your program will not need to go, if you still Turn instead of garbled. 2, in the POST request, do not consider the point, as long as write a character filter all the cloth set to Utf-8, you can avoid garbled. These need to be tested over and over again to have a deeper understanding.
HTTP requests are iso-8859-1 encoded to transmit the URL if the Content-type of the page is Utf-8, then when the request is sent, the character will be transferred to Utf-8 after it is transferred such as: UTF-8 E4 the ad is B8 on request Ad bytes are% separated then the server receives this byte stream, it must be converted to the corresponding character, the usual Request.getparameter ("name") to get the string directly, then from the stream of bytes to the word stream the process system has been helped us to complete ( This starts with garbled characters) similar to the following program: Convert the UTF-8 form of Chinese character "Zhong" into Chinese public class Encodingtest {public static void main (string[] args) {String utf_ string = "E4%b8%ad";//UTF-8 encoding, three bytes, separated by% string[] Utf_array = utf_string.split ("%"); byte[] Utf_byte = new Byte[utf_ array.length];for (int i=0;i<utf_array.length;i++) {Utf_byte[i] = (byte) integer.parseint (Utf_array[i], 16);} try {System.out.println (new String (Utf_byte, "UTF-8")),} catch (Unsupportedencodingexception e) {//TODO auto-generated Catch Blocke.printstacktrace ();}}} Note The segment code: new String (Utf_byte, "UTF-8") that restores the byte stream to UTF-8 encoding as a string, but it uses the precondition that utf_byte must be a byte stream of utf-8, if so: String AA = "medium"; bb = Aa.getbytes ("Iso-8859-1"); new String (BB, "UTF-8") must be garbled. This means that a string is converted into a byte stream with what encoding it has to be restored bb=aa.getbytes (" UTF-8 ") must be new String (BB," UTF-8 ") otherwise garbled: URL through iso-8859-1 transmission, the server received this byte stream,By default, this byte stream is reverted to the corresponding string as Iso-8859-1: the client: BB = aa.getbytes ("UTF-8"), to the server: CC = new String (BB, "iso-8859-1") The restore byte stream is a section character string Request.getparameter (""); get to this cc, then CC is of course garbled, so there is the practice: New String (Request.getparameter (""). GetBytes (" Iso-8859-1 ")," UTF-8 ") reverts to the original string, restores the garbled string to the original byte stream, and re-presses the UTF-8 to encode. This is because
Request.getparameter ("") is actually a iso-8859-1 decoding, and then get a garbled string, then you have to re-press ISO-8859-1 encoded into a byte stream, and then in the
String (BB, "UTF-8") is decoded as a character stream by UTF-8.
As for changing uri-encoding in Tomcat and using filters, I'm guessing to change the encoding of bytes into strings
Here is just my point of view, wrong, please correct me