Garbled processing and encoding format

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.