Tomcat deployment project garbled summary, tomcat deployment project garbled

Source: Internet
Author: User

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.

  • Project code

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.

  • Tomcat Encoding

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.