Home >Operation and Maintenance >CentOS >What should I do if Chinese garbled characters appear in tomcat under centos?

What should I do if Chinese garbled characters appear in tomcat under centos?

王林
王林Original
2020-05-21 16:02:242135browse

What should I do if Chinese garbled characters appear in tomcat under centos?

1. Set the locale of the current system to Chinese

[root@iZ25bdzgev8Z ~]# locale  #查看当前系统的语言环境
[root@iZ25bdzgev8Z ~]# yum -y install kde-l10n-Chinese  #安装中文语言包, yum源配置在阿里
[root@iZ25bdzgev8Z ~]# yum reinstall glibc-common
[root@iZ25bdzgev8Z ~]# LANG="zh_CN.UTF-8"

2. Edit the server.xml file and make the following modifications

<Connector port="9999" protocol="HTTP/1.1"
    connectionTimeout="20000" URIEncoding="UTF-8"  useBodyEncodingForURI=”true”
    redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"   />

3. Edit The database connection file /var/lib/tomcat/webapps/myproject/WEB-INF/classes/config.properties under the project is modified as follows:

jdbc.url=jdbc:mysql://IP地址:3306/ myprojectDB?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true

4. Modify the Web.xml file

<servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>cn.hncu.servlets.LoginServlet</servlet-class>
    <init-param>
        <param-name>character</param-name>
        <param-value>GBK</param-value>
    </init-param>
</servlet>

5. Character settings for mysql

mysql> show variables like &#39;character_set_database&#39;;
mysql> alter database 库名 CHARACTER SET utf-8;

Recommended tutorial: centos tutorial

The above is the detailed content of What should I do if Chinese garbled characters appear in tomcat under centos?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn