SpringMVC关于接收Form表单POST请求时,中文参数乱码的问题
程序员文章站
2022-07-15 11:58:29
...
SpringMVC接收Form表单POST请求时,中文参数出现乱码的问题?(GET请求时,不会乱码)
原因:Form表单提交POST请求时,中文参数会出现编码格式为ISO8859-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>