The ultimate solution to the problem of Chinese garbled characters in tomcat static pages (html)

The ultimate solution to the problem of Chinese garbled characters in tomcat static pages (html)

In tomcat, jsp is not garbled, but html Chinese is garbled

There are several reasons:

The page encoding is not set. The configuration of Tomcat is incorrect. The encoding format of the saved file is not utf-8. Let's discuss the solution below.

The html page is set to utf-8 and the <meta> tag is added to the page header

insert image description here

tomcat server.xml configuration

(1) Add URIEncoding="UTF-8"

<Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" URIEncoding="UTF-8" />

(2)

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

Set catalina.bat in tomcat (jvm encoding)

In catalina.bat, add below set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%" : -Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8
As shown below:

set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"
-Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8

Set tomcat's web.xml (mine is around line 108) to the following:

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

The above is the solution to solve the garbled code of Tomcat . You need to restart Tomcat after configuration.

Restart tomcat:

If your toamcat is already started: enter the tomcat installation directory in the command line
C:\tomcat\bin>stutdown
Then C:\tomcatbin>startup
This completes a restart of tomcat.

This is the end of this article on the ultimate solution to the Chinese garbled problem in tomcat static pages (html). For more relevant content on the Chinese garbled problem in tomcat static pages, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the problem of Chinese garbled characters in SpringMVC, tomcat, Intellij idea and ajax
  • Solve the Chinese garbled problem when Java & Idea start tomcat
  • Solve the problem of Chinese garbled characters when inserting data into MySQL by Tomcat under Linux
  • How to configure the character set of Tomcat server to utf-8 to completely solve the problem of Chinese garbled characters

<<:  Button is stretched on both sides in IE

>>:  CSS implementation code for drawing triangles (border method)

Recommend

JavaScript uses setTimeout to achieve countdown effect

In order to enhance the ability to write JavaScri...

Detailed explanation of JS variable storage deep copy and shallow copy

Table of contents Variable type and storage space...

A brief discussion on the problem of Docker run container being in created state

In a recent problem, there is such a phenomenon: ...

The meaning of the 5 types of spaces in HTML

HTML provides five space entities with different ...

What are the benefits of using B+ tree as index structure in MySQL?

Preface In MySQL, both Innodb and MyIsam use B+ t...

How to open external network access rights for mysql

As shown below: Mainly execute authorization comm...

Use neat HTML markup to build your pages

The Internet is an organism that is constantly ev...

MySQL batch adding and storing method examples

When logging in to the stress test, many differen...

Use of Vue3 table component

Table of contents 1. Ant Design Vue 1. Official w...

Detailed graphic tutorial on installing centos7 virtual machine in Virtualbox

1. Download centos7 Download address: https://mir...

jQuery clicks on the love effect

This article shares the specific code of jQuery&#...

Detailed examples of Zabbix remote command execution

Table of contents one. environment two. Precautio...