Spring-解决请求中文乱码问题
解决spring请求中文乱码问题
1、web.xml添加编码拦截器
<filter>
<filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、jsp页面编码设置为UTF-8
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
3、以上修改只能解决post请求,tomacat对GET和POST请求处理方式是不同的,处理GET请求的编码问题,要修改tomcat安装目录的server.xml配置文件,在Connector标签添加URIEncoding="UTF-8"
<Connector connectionTimeout="20000"
port="8080"
protocol="HTTP/1.1"
redirectPort="8443"
URIEncoding="UTF-8"/>