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

Detailed explanation of MySQL alter ignore syntax

When I was at work today, the business side asked...

JS implements the dragging and placeholder functions of elements

This blog post is about a difficulty encountered ...

Vue realizes dynamic progress bar effect

This article example shares the specific code of ...

Detailed tutorial on installing JDK1.8 on Linux

1. Cleaning before installation rpm -qa | grep jd...

How to implement communication between Docker containers

Scenario: A laradock development environment (php...

HTML Frameset Example Code

This article introduces a framework made by Frame...

Several ways to store images in MySQL database

Usually the pictures uploaded by users need to be...

Summary of Mysql common benchmark commands

mysqlslap Common parameter description –auto-gene...

Vue+el-table realizes merging cells

This article example shares the specific code of ...

Graphical introduction to the difference between := and = in MySQL

The difference between := and = = Only when setti...

10 Underused or Misunderstood HTML Tags

Here are 10 HTML tags that are underused or misun...

Several methods to clear floating (recommended)

1. Add an empty element of the same type, and the...