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.