the solution of Java Chinese garbled problem--principle and check step
@for &ever 2009-10-21
I. Principles
The entire application of all parts, using a unified code.
second, the inspection steps
Depending on the principles above, you can consider the following steps:
For example, select a uniform UTF-8 encoding (similar to other encodings);
1 , the encoding of the file
Open a text file (HTML, FTL, JSP, shtml) using a tool such as EmEditor to set the encoding, and save the file as a UTF-8 encoded encoding format
2 , UrlEncode
If it involves passing parameters through a URL, you need to set it.
The value of the parameter is usually UTF-8 encoded using Urlencoder.encode.
3 , Filter the configuration
Consider adding a global filter filter to set the encoding UTF-8.
4 , the server operating system encoding configuration
Windows systems generally do not have problems, and Linux systems need to set the system's encoding.
Modify/etc/sysconfig/i18n file to increase
Lang= "en_US. UTF-8 "
Lang= "ZH_CN. UTF-8 "
Lang= "ZH_CN. GB18030 "
Lang= "zh_cn.gb2312"
And so on and make the changes take effect
5 , the Application server encoding configuration
For example, for Tomcat, you can modify
<connector executor= "Tomcatthreadpool"
port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
redirectport= "8443"/>
Paragraph, increase
Uriencoding= "UTF-8"
6 , DB the encoding configuration
The DB encoding is also set to be the same as the global encoding.
For example, for MySQL, all tables are created, adding Charset=utf8 settings.
7 , other
When the Java code is connected to the database, the connection string is written to add the encoding settings.
For example, add Characterencoding=utf8
Jdbc:mysql://localhost:3306/forandever?characterencoding=utf8
@forandever 2009-10-21