Tomcat URL乱码
程序员文章站
2022-07-14 12:46:44
...
我们在开发REST服务的时候,尤其是做中文项目的时候,会遇到传入参数乱码的问题,这个就比较麻烦了,因为原因真的很复杂,根本不止我所列的两个地方,还得具体问题具体分析了。
如果你用的是Spring MVC,首先要检查一下CharacterEncodingFilter是否配置了编码
然后再看一下Tomcat的server.xml是否配置了编码
http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html#Common_Attributes
然后就好用了哦~
如果你用的是Spring MVC,首先要检查一下CharacterEncodingFilter是否配置了编码
<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> <url-pattern>/*</url-pattern> </filter-mapping>
然后再看一下Tomcat的server.xml是否配置了编码
http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html#Common_Attributes
<!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
然后就好用了哦~