SpringMvc发送post请求中文乱码问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qiesheng/article/details/75158621

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>

2.若配置统一过滤器之后还是乱码,需要在controller的@RequestMapping中添加参数produces

例如: @RequestMapping(value = "/uploadData",method=RequestMethod.POST,produces=MediaType.TEXT_PLAIN_VALUE)

猜你喜欢

转载自blog.csdn.net/qiesheng/article/details/75158621