Table of Contents
locale -a (list the names of all available public locale environments)
##   Properties->Terminal (the terminal connection tool I use is Xshell. For other connection tools, please change the encoding method on Baidu)
Home Operation and Maintenance Linux Operation and Maintenance How to solve the Chinese garbled characters in Tomcat logs?

How to solve the Chinese garbled characters in Tomcat logs?

Jul 27, 2017 pm 03:27 PM
centos7 Garbled characters language

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

## Tomcat output log Chinese garbled code

System environment

  • CentOS 7.0 64-bit

  • ##jdk-8u11-linux-x64.
  • ##apache-tomcat-8.5. 16
  • ## Solution steps:

  • 1. Install the Chinese language pack

First check whether the Chinese language pack is installed on the system

locale -a (list the names of all available public locale environments)

                                                                     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

    Then each item can be commonly understood as "You speak Chinese, you are in China, and the language character set is gb18030/gb2312/utf8"

                                              ccosten in us\If the above items are not found, manually install the Chinese language Package

         

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

  

 ("en_US.UTF-8" can be understood as "you speak English, you are in the United States, and the language character set is UTF-8" according to the above content)  
     Each item The meanings are:

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

LC_MONETARY: Currency unit

LC_MESSAGES: The information is mainly prompt information, error information, status information, title, label, button and menu, etc.

LC_NAME:Name writing method

LC_ADDRESS:Address writing method

LC_TELEPHONE:Phone number writing method

LC_MEASUREMENT:Weights and measures expression

LC_PAPER: Default paper size

LC_IDENTIFICATION: Overview of the information contained in the locale itself

LC_ALL: The highest priority variable. If this variable is set, all LC_* and LANG variables will be forced to follow. Its value

We see that although the Chinese language pack is installed, the locale of the machine is not Chinese. First modify the i18n configuration file

vim /etc/sysconfig/i18n

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

##                       

          

##          

##                      

##                                

##        

##   Properties->Terminal (the terminal connection tool I use is Xshell. For other connection tools, please change the encoding method on Baidu)

  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

# cd $CATALINA_HOME

# tail -f ./logs/catalina.out

#, 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

Send a request to the server

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CentOS7 various version image download addresses and version descriptions (including Everything version) CentOS7 various version image download addresses and version descriptions (including Everything version) Feb 29, 2024 am 09:20 AM

When loading CentOS-7.0-1406, there are many optional versions. For ordinary users, they don’t know which one to choose. Here is a brief introduction: (1) CentOS-xxxx-LiveCD.ios and CentOS-xxxx- What is the difference between bin-DVD.iso? The former only has 700M, and the latter has 3.8G. The difference is not only in size, but the more essential difference is that CentOS-xxxx-LiveCD.ios can only be loaded into the memory and run, and cannot be installed. Only CentOS-xxx-bin-DVD1.iso can be installed on the hard disk. (2) CentOS-xxx-bin-DVD1.iso, Ce

How to solve Chinese garbled characters in Linux How to solve Chinese garbled characters in Linux Feb 21, 2024 am 10:48 AM

The Linux Chinese garbled problem is a common problem when using Chinese character sets and encodings. Garbled characters may be caused by incorrect file encoding settings, system locale not being installed or set, and terminal display configuration errors, etc. This article will introduce several common workarounds and provide specific code examples. 1. Check the file encoding setting. Use the file command to view the file encoding. Use the file command in the terminal to view the encoding of the file: file-ifilename. If there is "charset" in the output

3 Ways to Change Language on iPhone 3 Ways to Change Language on iPhone Feb 02, 2024 pm 04:12 PM

It's no secret that the iPhone is one of the most user-friendly electronic gadgets, and one of the reasons why is that it can be easily personalized to your liking. In Personalization, you can change the language to a different language than the one you selected when setting up your iPhone. If you're familiar with multiple languages, or your iPhone's language setting is wrong, you can change it as we explain below. How to Change the Language of iPhone [3 Methods] iOS allows users to freely switch the preferred language on iPhone to adapt to different needs. You can change the language of interaction with Siri to facilitate communication with the voice assistant. At the same time, when using the local keyboard, you can easily switch between multiple languages ​​to improve input efficiency.

How to solve the problem of Chinese garbled characters in Windows 10 How to solve the problem of Chinese garbled characters in Windows 10 Jan 16, 2024 pm 02:21 PM

In the Windows 10 system, garbled characters are common. The reason behind this is often that the operating system does not provide default support for some character sets, or there is an error in the set character set options. In order to prescribe the right medicine, we will analyze the actual operating procedures in detail below. How to solve Windows 10 garbled code 1. Open settings and find "Time and Language" 2. Then find "Language" 3. Find "Manage Language Settings" 4. Click "Change System Regional Settings" here 5. Check the box as shown and click Just make sure.

Steps to enter CentOS 7 emergency repair mode Steps to enter CentOS 7 emergency repair mode Jan 13, 2024 am 09:36 AM

Open the centos7 page and appear: welcome to emergency mode! afterloggingin, type "journalctl -xb" to viewsystemlogs, "systemctlreboot" toreboot, "systemctldefault" to tryagaintobootintodefaultmode. giverootpasswordformaintenance(??Control-D???): Solution: execute r

Methods and detailed analysis to solve the problem of garbled characters in some win11 software Methods and detailed analysis to solve the problem of garbled characters in some win11 software Jan 30, 2024 pm 03:54 PM

Many users found that their personal software was garbled after upgrading the win11 system. So how to solve this problem? Now let the editor carefully introduce to users the analysis of garbled code problems in some software in win11. Analysis of garbled characters in some software in win11 1. Click the search box in the taskbar in the lower left corner and enter control panel to open it. 3. Click on the area. 5. Then uncheck the small box for beta version in the window, and finally restart the computer to solve the problem.

How to solve the problem of garbled characters when importing Chinese data into Oracle? How to solve the problem of garbled characters when importing Chinese data into Oracle? Mar 10, 2024 am 09:54 AM

Title: Methods and code examples to solve the problem of garbled characters when importing Chinese data into Oracle. When importing Chinese data into Oracle database, garbled characters often appear. This may be due to incorrect database character set settings or encoding conversion problems during the import process. . In order to solve this problem, we can take some methods to ensure that the imported Chinese data can be displayed correctly. The following are some solutions and specific code examples: 1. Check the database character set settings In the Oracle database, the character set settings are

Tips for dealing with garbled Chinese file names in PHP Tips for dealing with garbled Chinese file names in PHP Feb 27, 2024 pm 02:18 PM

Tips for dealing with garbled Chinese file names in PHP During the development process, we often encounter the problem of garbled Chinese file names, especially when processing files uploaded by users. In PHP, how to correctly handle garbled file names is a common and important problem. This article will introduce some techniques for dealing with garbled Chinese file names and provide specific code examples to help readers better deal with this challenge. Problem description: When users upload files, the Chinese file names sometimes appear to be garbled. This is because different operating systems and browsers

See all articles