The solution is at the end of the article, you can slide down to the bottom to browse directly
Today, when I used Tomcat to access the static page, there was a problem of garbled characters on the page. After trying various methods, my heart was on the verge of collapse. After going out for a run to calm down, my thoughts gradually became clear.
The first step after garbled characters is to check the encoding settings. Click file to select setting, and change the following places.
Then, choose to set the code for the new project (you can set it according to your personal needs), and the location is still set as shown above after entering.
At this point, IDEA's encoding setting is complete, but after I start Tomcat, the HTML page appears garbled characters directly, so I want to check the encoding format specified by the response header of the page first. Bo this came directly, and I was confused.
Did you think this was the end of the story? How can it be. That being the case, it must be a problem with the Tomcat server. I decisively changed to a Tomcat8 server. However, the previous Tomcat9 is still garbled.
Many friends on the Internet said to find the server.xml configuration file in the Tomcat installation directory, and then add URIEncoding="UTF-8", just when I thought it would open the door to a new world, what I didn't expect was a blow to the head, or garbled characters .
Just when I was at a loss, I didn't expect to usher in a double score. Is it necessary to configure the encoding in the web.xml file, so I added the following code to the configuration file with the mentality of giving it a try:
<init-param>
<param-name>fileEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
The problem of Tomcat garbled characters has finally been solved. Let’s sum it up in a few points:
- The encoding format of the configuration file in IDEA is utf-8
- Tomcat's server.xml file adds utf-8 encoding settings
- You also need to configure the encoding format of Tomcat's web.xml configuration file to be utf-8
The configuration file is in this directory