Skip to main content

Encoding problem of JSP in APACHE + TOMCAT environment

Mr.ChenLess than 1 minutearticleJava

Today I encountered the problem of garbled characters again, which is really annoying. Why can't TOMCAT automatically judge the encoding of the project, but the project must follow the encoding of TOMCAT.

Let's talk about the solution:

Add the URIEncoding="UTF-8" attribute to the connector in TOMCAT's SERVER.XML configuration file, such as

<Connector port="88" maxHttpHeaderSize="8192" maxThreads="20" minSpareThreads="5" maxSpareThreads="10"
enableLookups="false" redirectPort="8049" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8" />

If APACHE integrates TOMCAT, URIEncoding should also be set in the connected CONNECTOR

It is said on the Internet that AddDefaultCharset can be added to the httpd.conf configuration file of APACHE, such as

AddDefaultCharset Off
or
AddDefaultCharset=UTF-8

But I have tried AddDefaultCharset Off, I haven’t tried AddDefaultCharset=UTF-8, I can’t let the whole APACHE also fix the encoding.

Finally, the sentence, why can’t TOMCAT follow the code of the project, sad!!!!!