解决方法:在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>
<!--强制指定字符编码,即如果在request中指定了字符编码,那么也会为其强制指定当前设置的字符编码--> <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>
参考文章:
http://www.monkey1024.com/framework/1272
https://blog.csdn.net/qq_37164975/article/details/82498559