Servlet and JSP Chinese garbled problem summary _ Jian

Source: Internet
Author: User

Forword:

For cainiao such as Jian, Chinese garbled characters are a headache During javaee projects.

Today, I will dedicate this virgin blog to you, Chinese brother.

 

Question_1: [Garbled Chinese Characters in JSP content display]

If the JSP page does not interact with any servlet, Chinese garbled characters are displayed, and the encoding settings of the page header are carefully observed, such:

 

<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "ISO-8859-1" %> 

 

Change the encoding property value to pageencoding = "GBK" for normal display (of course, you can also set it to "UTF-8" or "gb2312 ")

It is recommended that the encoding method be consistent. For example, Jian decides to use "GBK" in the same way, because the word is the least...

 

Question_2: [Chinese garbled characters appear during jump between JSP and Servlet]

Case 1: method = "Post"

In JSP, when the form is submitted with ation = "xxxservlet" and method = "Post", the attributes of Chinese characters are often found to be garbled after being obtained in the servlet.

In this case, locate the dopost () method and add the following code to the first line of the method:

 

Request. setcharacterencoding ("GBK ");

 

It indicates that the request is encoded as "GBK", which is generally consistent with the JSP page.

Then, add the Code:

 

Response. setcharacterencoding ("GBK ");

Response. setcontenttype ("text/html; charset = GBK ");

 

It means to set the response encoding to "GBK", that is, the encoding when the servlet returns the JSP. You can use either of the above two segments. Consistency is the key.

 

Case 2: method = "get"

In JSP, when the form is submitted with ation = "xxxservlet" and method = "get", the attributes of Chinese characters are often found to be garbled after being obtained in the servlet.

In this case, you need to locate the tomcat installation directory % Tomcat %/CONF/server. xml file

Find the following code snippet:

 

<Connector Port = "8080" protocol = "HTTP/1.1" <br/> maxthreads = "150" <br/> connectiontimeout = "20000" <br/> redirectport = "8443 "<br/> uriencoding =" GBK "/>

 

Finally, uriencoding = "GBK" is manually added by Jian to solve the problem of Chinese garbled get.

 

Conclusion:

I briefly summarized some common Chinese garbled characters in Servlet and JSP. Jian should make more technical summaries to learn more about it...

 

Confusion:

Consider <a href = "xxxservlet? In the flag =### "> hyperlink </a>, ### it seems that there is a problem in converting it to Chinese. Remember that it was encountered before and has not been solved yet.

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.