1、设置当前系统的语言环境为中文
[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. 编辑server.xml文件,进行如下修改
<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、编辑项目下的数据库连接文件/var/lib/tomcat/webapps/myproject/WEB-INF/classes/config.properties,修改如下:
jdbc.url=jdbc:mysql://IP地址:3306/ myprojectDB?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true
4、修改Web.xml文件
<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、针对mysql进行字符设置
mysql> show variables like 'character_set_database'; mysql> alter database 库名 CHARACTER SET utf-8;
推荐教程:centos教程