The Chinese language of the Linux system is garbled, which is a problem that many friends often encounter when they first come into contact with Linux. Moreover, when we move the projects that have been deployed in Wndows to run on Linux, the Chinese output logs of Tomcat are all garbled. (Normal on Windows), it looks very frustrating, so how should we solve it?
System Chinese garbled code
## Solution steps:
First check whether the Chinese language pack is installed on the system
machines in her in in in on in on in on in on in on in on the names in all available public locales What do several items mean?
{Language code}_{Country code}.{Character set}
zh is the code for Chinese, CN is the code for China, gb18030, gb2312, utf8 is the language character set
yum install kde-l10n-Chinese somehow 11M in about 11M
# Before modifying the configuration file, let’s take a look at the current system locale
LANG: The language of the current system LC_CTYPE: Language symbols and their classification
LC_NUMERIC: Numbers LC_COLLATE: Comparison and sorting Habit
LC_TIME: Time display format
Add the following two lines of code LANG="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"
# source /etc/sysconfig/i18n Modify the locale.cnf configuration file
# vim /etc/locale.conf
LANG="zh_CN.UTF-8"
## shall should should should be 10-100ml
##
####
##Change the encoding to UTF-8
Reconnect and check the current system locale
Locale
It is found that the system locale has been successfully changed to "zh_CN.UTF-8"
Try editing Chinese again
# SUCCESS! At this point, the problem of garbled Chinese characters in the system has been solved. 4. Solve the problem of garbled Chinese characters in the Tomcat output log
Now that the Chinese garbled characters in the system have been solved, will the Chinese garbled characters in the Tomcat output log also be solved?
Let’s take a look at the Tomcat output log now
Enter the Tomcat directory
#, Tomcat log Chinese is still garbled.
Analysis: Since Chinese garbled characters no longer appear in the system, it proves that the system language environment is normal, but Chinese garbled characters still appear in the Tomcat log, indicating that it is an internal problem of Tomcat. I checked some information online and found that it is the JVM. (Java Virtual Machine)
The character set used by the Java virtual machine is inconsistent with the character set used by the system. If you know the reason, the problem will be solved. You can modify the JVM startup parameters by configuring the JVM startup parameters. Character set purpose.
# ls -l ./bin/
Find daemon.sh and catalina.sh and add the following codes respectively:
JAVA_OPTS= "$JAVA_OPTS -Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.language=zh_CN -Dsun.jnu.encoding=UTF-8"
# vim ./ bin/daemon.sh
# vim ./bin/catalina.sh
Save and exit, restart Tomcat # ./bin/shutdown.sh
# ./bin/startup.sh
Now check the output log
# tail -f ./ logs/catalina.out
The above is the detailed content of How to solve the Chinese garbled characters in Tomcat logs?. For more information, please follow other related articles on the PHP Chinese website!