My Chinese questions

Source: Internet
Author: User

Many people have encountered Chinese garbled characters, and there are also more than N solutions. This is one of the problems I encountered.


Environment:

1. centos

2. jdk1.7

3. tomcat7

4. Git

5. ant1.9.4


Symptom:

1. The JAVA source code is UTF-8 encoded, but the Chinese output is garbled;

2. My webapp requires English by default, but Chinese (some content is read from the property file );


Other information:

1. Default System Language

LANG="en_US.UTF-8"SUPPORTED="en_US.UTF-8:en_US:en"SYSFONT="latarcyrheb-sun16"/etc/sysconfig/i18n (END) 

2. The default language for starting Tomcat is:

LANG=zh_CN.UTF-8LC_CTYPE="zh_CN.UTF-8"LC_NUMERIC="zh_CN.UTF-8"LC_TIME="zh_CN.UTF-8"LC_COLLATE="zh_CN.UTF-8"LC_MONETARY="zh_CN.UTF-8"LC_MESSAGES="zh_CN.UTF-8"LC_PAPER="zh_CN.UTF-8"LC_NAME="zh_CN.UTF-8"LC_ADDRESS="zh_CN.UTF-8"LC_TELEPHONE="zh_CN.UTF-8"LC_MEASUREMENT="zh_CN.UTF-8"LC_IDENTIFICATION="zh_CN.UTF-8"LC_ALL=

3. There is no problem with vim Java source code in Chinese.

4. Modify the language of the Tomcat user:

Export lang = en_us

Result: A Chinese characters are garbled; B webapp is in English (correct) by default)


Final Solution

1. Add parameters when compiling Java code: javac encoding = "UTF-8"

2. Modify the Tomcat STARTUP script start. SH and add: Export lang = en_us at the beginning.

Note: Do not modify your default language.


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.