9.1 题目
Spring MVC 中如何解决 POST 请求中文乱码问题,GET 又是如何处理的呢?
9.2 解决方式
POST 请求:web.xml 中配置过滤器
<!--解决POST请求的请求乱码问题–->
<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>
GET 请求:修改 Tomcat 配置文件 server.xml,第一个
标签 <Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" maxPostSize="0"/>