解决springmvc的get提交和post提交的中文乱码问题

时间:2021-08-18 13:06:10

1.post提交出现的中文乱码问题

解决办法:在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>

2.get提交出现的中文乱码问题

解决办法:在tomcat的server.xml中

 <Connector port="8080" protocol="HTTP/1.1"  connectionTimeout="20000" redirectPort="8443"/>

添加useBodyEncodingForURI="true"和URIEncoding="UTF-8"