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.