spring mvc请求参数中文乱码解决方案

时间:2021-09-16 21:08:09

POST 请求

在web.xml中加上增加过滤器

 <filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

GET 请求

修改 Tomcat根目录的 conf/server.xml文件,找<Connector port="8080" />,在里面加<Connector port="8080" URIEncoding="utf-8" />