标签:and query coding play line server using star class
Tomcat7对URI默认编码是ISO-8859-1
Tomcat8对URI默认编码是UTF-8
官网解释:
https://tomcat.apache.org/tomcat-7.0-doc/config/http.html
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.
https://tomcat.apache.org/tomcat-8.0-doc/config/http.html
URIEncoding :This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, UTF-8 will be used unless the org.apache.catalina.STRICT_SERVLET_COMPLIANCE system property is set to true in which case ISO-8859-1 will be used.
在Tomcat包内也可以查找到:webapps→docs→config→http.html
以Tomcat8为例:
(1)、URIEncoding
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, UTF-8 will be used unless the org.apache.catalina.STRICT_SERVLET_COMPLIANCE system property is set to true in which case ISO-8859-1 will be used.
(2)、useBodyEncodingForURI
This specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding. This setting is present for compatibility with Tomcat 4.1.x, where the encoding specified in the contentType, or explicitly set using Request.setCharacterEncoding method was also used for the parameters from the URL. The default value is false.
Notes: 1) This setting is applied only to the query string of a request. Unlike URIEncoding it does not affect the path portion of a request URI. 2) If request character encoding is not known (is not provided by a browser and is not set by SetCharacterEncodingFilter or a similar filter using Request.setCharacterEncoding method), the default encoding is always "ISO-8859-1". The URIEncoding setting has no effect on this default.
可以理解为:
设置URIEncoding参数可以是对所有GET方式的请求的数据进行统一的重新编码,默认编码为 UTF-8;
设置useBodyEncodingForURI为true时,请求查询参数的编码和contentType的设置一致
<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
redirectPort="443" URIEncoding="UTF-8" />
URIEncoding只对URL中的参数进行编码
设置useBodyEncodingForURI=true时,就会将请求参数和请求体中的参数根据request.setCharacterEncoding或者contentType中的字符集编码。
servlet等Java后台程序中使用request.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");这个方法对于请求Body中的字符编码才有作用,也就是基本只对POST产生作用,终究的原因是GET是HTTP服务器处理,而POST是WEB容器处理
<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>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>9080</port>
<server>tomcat7</server>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
标签:and query coding play line server using star class
原文地址:https://www.cnblogs.com/Dreamice/p/11780776.html