Solutions to Chinese garbled web pages and Chinese Garbled text

Source: Internet
Author: User

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

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.