欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Tomcat URL乱码

程序员文章站 2022-07-14 12:46:08
...
我们在开发REST服务的时候,尤其是做中文项目的时候,会遇到传入参数乱码的问题,这个就比较麻烦了,因为原因真的很复杂,根本不止我所列的两个地方,还得具体问题具体分析了。
Tomcat URL乱码
            
    
    博客分类: Tomcat tomcatspring 

如果你用的是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是否配置了编码
Tomcat URL乱码
            
    
    博客分类: Tomcat tomcatspring 
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"/>


然后就好用了哦~
Tomcat URL乱码
            
    
    博客分类: Tomcat tomcatspring 

相关标签: tomcat spring