When a database or page appears garbled in Chinese, it is often necessary to analyze it from the following places
1. Page encoding
2. Database connection statement (if the data connection's properties file encoding inconsistent with the database encoding format will result in data stored in the database garbled regardless of Chinese and English consent garbled)
- Set characterencoding to UTF-8 such as jdbc.mysql.url=jdbc:mysql://localhost:3306/db?useunicode=true& Characterencoding=utf8
- If you use Hibernate, change the encoding format of all configuration file headers to UTF-8.
3.Tomcat
- In order to ensure that the Get/post data uses the same UTF8 encoding, we set the following settings in Server.xml: <connector port= "8080" protocol= "http/1.1" Connectiont imeout= "20000" redirectport= "8443" uriencoding= "UTF-8"/>
4. STRUTS2 Configuration
- Struts2 add Struts.i18n.encoding=utf-8 to the configuration struts.properties file or add <constant name= in Struts.xml Struts.i18n.encoding "value=" UTF-8 "/>
Configure the filter in the Web. xml file
<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>
5. Database (MySQL)
You can first enter the query statement show VARIABLES like ' character_set_% ';, to see if all the encodings are UTF-8.
If you are not able to use the Server Instance Config to set the default character set to Utf-8 or modify DEFAULT-CHARACTER-SET=GBK in/mysql/mysql Server 5.0/my.ini
CHARACTER-SET-SERVER=GBK;
And then restart the MySQL service.
Solve the problem of storing Chinese data in database garbled, garbled pages, etc.