The solution of Java Chinese garbled problem--principle and check steps __ garbled problem

Source: Internet
Author: User

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

Related Article

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.