When using IDEA, about the problem of Tomcat processing garbled HTML requests (after accessing the static page F12 of the server, the encoding format in the response header is utf-8, or garbled)

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.

insert image description here 

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.

insert image description here

 

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:

insert image description here

 

<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:

  1. The encoding format of the configuration file in IDEA is utf-8
  2. Tomcat's server.xml file adds utf-8 encoding settings
  3. You also need to configure the encoding format of Tomcat's web.xml configuration file to be utf-8

insert image description here
The configuration file is in this directory

 

Guess you like

Origin blog.csdn.net/ok060/article/details/131526633