1、设置eclipse中全局编码为UTF-8
- Window→Preferences→General→WorkSpace→Text file encoding
2、设置JSP页面为UTF-8编码
- <%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%>
- 右键→Preferences→Encoding
3、Tomcat服务器server.xml中设置UTF-8编码
<Connector connectionTimeout="2000" port="9999" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
4、web.xml中配置编码过滤器(注:要配置在所有过滤器的前面)
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>