Tomcat deployment project garbled summary, tomcat deployment project garbled
If the packaged war package is placed under tomcat, Chinese characters may be garbled. First, determine the project encoding format, tomcat encoding format, and cmd command line encoding format.
Convert string to UTF-8 that will output to the console or log
1 String words = "UTF-8 encoding"; 2 words = new String (words. getBytes ("GBK"), "UTF-8 ");
Run the package again to check whether the code is garbled.
The system code is used by default when tomcat is started. You can change the catalina. bat file in the tomcat bin directory and add
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MaxPermSize=1024m -Dfile.encoding=UTF8
Xms and xmx set the minimum memory and maximum memory occupied by tomcat,-Dfile. encoding = UTF8 set the tomcat encoding format
- Cmd command line encoding
Set this item because when tomcat is started using startup. bat, it reads the code of catalina. bat and opens a new window for running. The default cmd code opened by tomcat may not be UTF-8, leading to garbled characters.
Open the registry, find HKEY_CURRENT_USER → Console → Tomcat, find the CodePage entry, create if no, change the value to 65001 in decimal format, and click OK.
Or directly copy the following code, save it as a. bat file, and run it directly.
set rr="HKCU\Console\Tomcat"reg add %rr% /v "CodePage" /t REG_DWORD /d 0x0000fde9 /f>nul
Restart tomcat.