1. Response: return the page from the server:
1. Set charset = GBK in JSP
2. response. setcontenttype ("text/XML; charset = GBK ")
2. Request: Go to the server and then to the database
1. Get and post requests:
New String (strobj. getbytes ("iso-8859-1"), "GBK ")
2. POST request:
A. Request. setcharacterencoding ("GBK ");
B. You can set filter interception.
3. GET request:
Step 1. First Configure the server settings, such as Tomcat: In its \ conf \ Server. xml:
<Connector Port = "8080" protocol = "HTTP/1.1"
Connectiontimeout = "20000"
Redirectport = "8443"
Uriencoding = "gb18030"/> // Add uriencoding settings
Step 2. Use java.net. urlencoding. encode () encoding for Chinese Characters in Java.
Iii. response. sendredirect redirection:
1. Use new string (strobj. getbytes ("iso-8859-1"), "GBK ")
2. Use the same processing as above:
Step 1. First Configure the server settings, such as Tomcat: In its \ conf \ Server. xml:
<Connector Port = "8080" protocol = "HTTP/1.1"
Connectiontimeout = "20000"
Redirectport = "8443"
Uriencoding = "gb18030"/> // Add uriencoding settings
Step 2. Use java.net. urlencoding. encode () encoding for Chinese Characters in Java, for example:
// Errormessage is a string
// Urlencoder. encode (errormessage, "gb18030") is used to convert the encoding format of errormessage to gb18030.
Response. sendredirect (request. getcontextpath () + "/basedata/My. jsp? Errormessage = "+ urlencoder. encode (errormessage," gb18030 "));
4. Spring garbled filter: org. springframework. Web. Filter. characterencodingfilter
Configuration in Web. xml:
<Filter>
<Filter-Name> encodingfilter </filter-Name>
<Filter-class> org. springframework. Web. Filter. characterencodingfilter </filter-class>
<Init-param>
<Param-Name> encoding </param-Name>
<Param-value> GBK </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-Name> encodingfilter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
Encoding range:
Gb18030: it overwrites all Unicode codes and is the default encoding format for Windows.
GBK: indicates both traditional and simplified Chinese characters.
Gb2312: it can only represent simplified Chinese characters.
Sort by the range containing Chinese characters gb18030> GBK> gb2312