在项目中遇到了使用get请求发送参数的时候在后台获取到数据是中文乱码,我首先想到的是没有配置比编码过滤器,但是检查过项目之后已经配置好了编码过滤器,对所有的url请求已经使用了utf-8的编码过滤器。 后来才想起来是tomcat编码配置问题。 修改tomcat的配置文件service.xml
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="utf-8" />
添加URIEncoding="utf-8"。解决get中文乱码问题。 我们再来引申一下tomcat其他参数的配置,难道你不想知道为什么可以这样配置吗,还有些什么配置参数可以配置的呢,看一下配置文件上面的这段注释
<!-- 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
-->
下面让我们打开tomcat文档 http://localhost:8080/docs/config/http.html 找到URIEncoding的参数说明
URIEncoding This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
你看,如果没配置的话默认是使用ISO-8859-1编码,我们项目是用utf-8de,所以就乱码了嘛。 等我有空的时候再看看其他有没有什么有用的参数。鉴于时间关系和英文水平有限,暂时就到这里