In the IDE, we usually set all the project-related coding to UTF-8, so we won’t discuss whether there is a problem with the project coding (if you are not sure, decomcompile the class file to see the Chinese in the text editor).

Two parts need to be modified: the console part of Windows and the log control part of Tomcat itself

Windows console

First you need to decide whether you want to modify all CMD Windows or just the CMD Windows generated by Tomcat.

If you want to modify all CMD Windows, see Operation 2. If you want to modify only Tomcat, see Operation 1.

(Modifying all CMD will cause some GBK encoded text to be garbled when operating programs in CMD, only tomcat will not have this problem.)

Bat reads the code of Catalina. bat and starts a new window. However, the default code of CMD is not UTF-8, resulting in garble characters.

Solutions:

1) Console part: Open the registry and press HKEY_CURRENT_USER→Console→Tomcat to find the CodePage entry. If not, set the value to 65001 in decimal.

Or directly copy the following code, save as any name. Bat file, run directly.

set rr="HKCU\Console\Tomcat"
reg add %rr% /v "CodePage" /t REG_DWORD /d 0x0000fde9 /f>nulCopy the code

Bat file is recommended, which is relatively simple.

After the preceding operations are complete, run startup.bat, right-click on the title bar of the CMD window, and click Properties

If the current code page is 65001, the modification is successful.

Operation 2. Enter regedit in the run to enter the registry

HKEY_CURRENT_USER \ Console \ % SystemRoot % _system32_cmd exe,

Create a new DWORD (32-bit value), name it CodePage and set it to 65001. If you already have a CodePage, change it to decimal 65001.

If the CMD is GBK, run the CHCP 65001 command.

After the modification, all CMD window encoding format is UTF-8.

2. Tomcat logs

After the above modification is successful, the console code has been changed to UTF-8, while Tomcat’s own log output code has not been modified, so some patients with OBSessive-compulsive disorder may need to modify Tomcat’s own log code.

Bat and startup.sh are used. The startup.

startup.bat————————

The catalina.bat file in the bin folder of Tomcat needs to be modified, as shown in the following figure



Add it after JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%

-Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8Copy the code

Encodeing changes the encoding format of the file, sun.jnu.encoding changes the encoding format of the file name.

After the modification, all contents in CMD were encoded as UTF-8, which satisfied patients with OBSessive-compulsive disorder.

startup.sh—————————–

Sh window encoding can be directly right-click on the title bar of the form, click Options, and change to UTF-8 in the pop-up box.

In the same way, modify the dialog box of Catalina. sh as shown in the following figure:



In – Djava. Util. Logging. Manager = org. Apache. Juli. Add after ClassLoaderLogManager

-Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8
Copy the code

——————————————

There’s an easy way to do this,

Bat call “%EXECUTABLE%” start %CMD_LINE_ARGS% “run”

The extra Catalina.bat window will no longer pop up.

Start. Sh in the same way.