The following analysis is based on the following assumptions:Unified encoding format using UTF-8
POST method:
Server:
In the first call request. when getparameter is used, parameter is parsed. If the encoding used for parsing (Decoding) is not set, the default encoding org is used. apache. coyote. constants. default_character_encoding ("ISO-8859-1") resolves the parameter. Therefore, if the parameter contains Chinese characters, garbled characters are parsed. Therefore, to support Chinese parsing, you must set the encoding format used for parsing parameters before calling request. getparameter for the first time, such:
Request. setcharacterencoding ("UTF-8 ");
Client:
Similarly, to enable the browser to support Chinese display on the client, you must set the webpage encoding format, for example:
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
Get method:
Client:
If the URI contains Chinese characters, it must be encoded:
<A href = "download? Filename = <% = java.net. urlencoder. encode (file, "UTF-8") %> "> <% = file %> </a>
Utf8 encoding is used here.
Server:
The server must know the encoding method used by the client and then decode it in the same way. You can tell the Server Client encoding method in server. xml:
<Connector connectiontimeout = "20000" Port = "8080" protocol = "HTTP/1.1"
Redirectport = "8443"Uriencoding = "UTF-8 "/>
<Connector Port = "8009" protocol = "AJP/1.3" redirectport = "8443"Uriencoding = "UTF-8 "/>
After the get method in form is submitted, the browser uses the encoding format of the current page to encode the Chinese parameter Uri, so human encoding is not required. Make sure the page encoding is utf8: <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">