新配置一个Spring的MVC项目。发现对Get请求的中文參数出现了乱码:
查看了SpingMVC中关于编码的配置(在web.xml中)。例如以下
<filter> <filter-name>encodingFilter</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>encodingFilter</filter-name> <servlet-name>appkit</servlet-name> </filter-mapping>
应该不是Spring的问题,应该是Tomcat的问题,然后去改动Tomcat的配置文件server.xml,加入URIEncoding="UTF-8"
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>然后就好了