1、tomcat里的server.xml两处加入URIEncoding="UTF-8"
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
修改之后可能启动eclipse,配置又会恢复为原样,需要删除掉eclipse里的tomcat,改完server.xml再重新添加tomcat到eclipse里就行。
2、连接字符串url加入?useUnicode=true&characterEncoding=UTF-8,例如下:
url:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false
3、查看mysql是否为utf-8
输入
show variables like '%char%';
查看是否都为utf8,修改mysql配置文件,
在[client]下添加
default-character-set=utf8
在[mysqld]下添加
character_set_server=utf8 init_connect= SET NAMES utf8
重启MySQL服务