“ 当content-type是"application/x-www-form-urlencoded; charset=utf-8"时,spring会自动设置request.setCharacterEncoding("UTF-8"),我用ajax方式提交的数据都是这样的content-type,没有乱码。但是form标签不能指定charset,spring默认设置的是Latin-1,所以会有乱码。虽然我在拦截器中已经setCharacterEncoding("UTF-8"),但是spring已经在这之前把浏览器发过的utf-8编码转成了Latin-1。 ”
————————————————
原文链接:https://blog.csdn.net/u012575700/article/details/50669588
解决办法:
在web.xml中添加如下配置:
<filter> <filter-name>Spring character encoding filter</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> </filter> <filter-mapping> <filter-name>Spring character encoding filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>