Solutions to Chinese garbled web pages and Chinese Garbled text
1. Solve the Problem of Chinese Characters in HTML pages: To make HTML pages support Chinese characters well, the following code must be added to the header of each HTML page:
<HEAD>
...
<META http-equiv = Content-Type content = "text/html; charset = gb2312">
...
<HEAD>
2. Solve the Problem of Chinese Characters in JSP pages. To make JSP pages support Chinese characters well, add the following code in the header of each JSP page:
<% @ Page contentType = "text/html; charset = gb2312" language = "java" %>
3. Solve the Problem of Servlet response results in Chinese. To make the Servlet page support Chinese well, you must add the following code in the header of each Servlet page:
Response. setCharacterEncoding ("gb2312 ");
4. Solve the Chinese problem of page data transmission. In order to make Chinese data normally transmitted between pages (components), the best solution is to use the encoding filter. Configure an encoding filter in WEB. XML with the following content:
<! -- Define the encoding filter -->
<Filter>
<Filter-name> encodingFilter </filter-name>
<Filter-class> org. springframework. web. filter. CharacterEncodingFilter </filter-class>
<Init-param>
<Param-name> encoding </param-name>
<Param-value> gb2312 </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-name> encodingFilter </filter-name>
<Url-pattern>/* </url-pattern>
</Filter-mapping>
5. solve the Chinese problem in HTTP (get) Request: by default, IE browser sends a "ISO-8859-1" encoding format to send the request, if the HTTP get request Chinese parameters are garbled, you can encode and convert it, for example:
String param = request. getParameter ("param ");
Param = new String (param. getBytes ("ISO-8859-1", "GB2312 "));
You can also modify the Tomcat server. xml file to solve the problem:
<Connection port = "8080"
...
URIEncoding = "GB2312"/> --> Add this
6. Solve the Chinese problem of MySQL database: Solve the Chinese problem of MySQL database mainly on the URL of the JDBC driver, for example:
Jdbc: mysql: // localhost/test? User = root & password = 123456 & useUnicode = true & characterEncoding = gb2312