今天开发的时候遇到这个问题,记性差,记下来先。
1、设置web.xml,添加utf-8拦截器
<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> <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> |
2、修改tomcat配置文件。
修改apache-tomcat-XXX\conf\server.xml文件,在<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8453"/>后面添加useBodyEncodingForURI="true" URIEncoding="UTF-8"。添加后如下:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" URIEncoding="UTF-8"/> |
时间: 2024-10-10 10:05:05