1、web.xml中加入编码过滤器配置:
<filter>
<filter-name>springUtf8Encoding</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>springUtf8Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、提交和接收方式都使用post
3、若后台还是接收到乱码,修改tomcat配置文件server.xml(eclipse绑定安装目录需要先删除server选项,修改配置后再重新添加服务器,否则无法修改):
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16596.html