tomcat设置“utf-8”
1. 配置文件server.xml.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding=
"UTF-8"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
URIEncoding=
"UTF-8"/>
2. 应用设置web.xml
通过filter节点设置
<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>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. JSP设置编码
3.1. pageEncoding: <%@ page pageEncoding="UTF-8"%>
jsp页面编码: jsp文件本身的编码
3.2. contentType: <%@ page contentType="text/html; charset=UTF-8"%>
web页面显示编码: jsp的输出流在浏览器中显示的编码
3.3. html页面charset: <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
web页面输入编码: 输入框输入的字体编码
4. 控制器方法设置编码
response.setContentType("application/
json");
response.
setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "text/html;charset=UTF-8");
5. apache设置编码
修改httpd.conf,
AddDefaultCharset off
AddDefaultCharset UTF-8