Spring MVC中文乱码问题
Spring MVC请求时经常出现中文乱码,查看配置文件,web.xml中已配置:1
2
3
4
5
6
7
8
9
10
11
12<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>
度娘后发现该配置只对post请求有效,对于get请求还要对tomcat的service.xml进行配置,具体配置如下:1
2<Connector connectionTimeout="20000" port="8080"
protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>
上面配置对ajax的get请求无效,如果要同时对ajax请求有效则改为1
2<Connector connectionTimeout="20000"
port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>