Solve the problem of Tomcat console and HTML garbled

1. Garbled console

This is because the default encoding of windows’s CMD is GBK, while Tomcat is UTF-8. Of course, there will be garbled codes. But for this garbled code, we just need to make the encoding format printed on the console GBK.

Modify the logging.properties configuration
and add it in the logging.properties configuration file under conf

java.util.logging.ConsoleHandler.encoding = GBK

Restart Tomcat to see that the console output log is normal

2. HTML page garbled

Modifying the web.xml file in Tomcat

<servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
		<init-param>
        	<param-name>fileEncoding</param-name>
        	<param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

I’ve also read many articles about modifying server.xml and catalina.bat, but they didn’t work for me. I tried to restore all Tomcat configurations, only modifying web.xml here, and finally determined that I only need to modify here

If you don’t succeed according to me, try to modify others!

Read More: