What should I do if the Chinese garbled characters in tomcat of Ubuntu Kirin system are encountered?

Time: 2017-08-03Source: Huajun InformationAuthor: youngest

After installing tomcat in the ubuntu Kirin system, users encountered garbled Chinese characters in tomcat when building the Demo program. Generally, garbled characters are caused by encoding problems. If your encoding settings are correct, the following reasons are Netizens who encounter this problem can take a look at the solutions prepared for everyone below.

What should I do if the Chinese garbled characters in tomcat of Ubuntu Kirin system are encountered?

The essence of garbled characters is that the character set is not uniform. If the character encoding of the content sent by your web browser to the server is inconsistent with the server encoding, then garbled characters will appear.

Solution:

(1) First unify the character encoding of the Linux server and configure it to utf-8.

(2) Configure the tomcat configuration file server.xml and change

Configured to:

(3) Configure the mysql database my.cnf and set the default character set to utf-8. Create the database after setting the database character set. Otherwise, inconsistent database character set information will lead to insertion errors.

Other solutions to the Chinese garbled problem under Tomcat

Common garbled code problems are now divided into two categories: JSP page display Chinese garbled code and form submission garbled code.

1) Chinese garbled characters are displayed in the JSP page

Use the page command in the JSP file to specify the MIME type of the response result, such as

2) Garbled characters in form submission

When the form is submitted (post and Get methods), the request.getParameter method is used to obtain garbled characters. This is because tomcat defaults to iso-8859-1 when processing submitted parameters. The problem of garbled characters in form submission get and post is different, which are explained below.

(1)POST processing

The form submitted by post is solved by writing a filter. The filter is called before the data submitted by the user is processed. You can change the encoding method of the parameters here. The code of the filter is as follows:

(2) Processing of Get method

Tomcat handles post and get differently, so the filter cannot solve the garbled problem of get. It needs to be set elsewhere.

Open the server.xml file in the conf directory, find the settings section of the Connector component that serves port 8080, and add an attribute to this component: URIEncoding="GBK". The modified Connector settings are:

* Note that restarting tomcat will take effect after modification.

Summary: The above is all the relevant content on how to deal with Chinese garbled tomcat in Ubuntu Kirin system. I don’t know if you already understand it.

The editor recommends:

How about Ubuntu Kirin? Ubuntu Kirin operating system performance

Ubuntu Kirin download address Ubuntu Kirin operating system official download

How to set up Apache virtual host in ubuntu 14.04

Related articles更多>>

Popular recommendations