1. 文件的编码确保是UFT-8:
workspace : eclipse -> window -> Preferences -> General -> Workspace -> Text file encoding 改成 UTF-8
项目是继承workspace的编码,也可以单独设置:右键项目,Properties -> Resource-> Text file encoding 改成 UTF-8
2. jsp 加上
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<Connector URIEncoding="UTF-8"
4. 过滤器filter,在web.xml:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
<url-pattern>*.htm</url-pattern>
</filter-mapping>
5.mysql的编码:
在my.ini文件里加上一句:
[mysql]
default-character-set=utf8
可以执行下列命令查询:
SHOW VARIABLES LIKE 'char%';