JavaWeb涓亣鍒扮殑瀛楃缂栫爜闂
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb涓亣鍒扮殑瀛楃缂栫爜闂相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/read' title='read'>read
exp enc 鍙傛暟 cti sed rom tchar bsp涓€銆佸父瑙佺殑缂栫爜鏂瑰紡
1銆乁TF-8
2銆両SO-8859-1
浜屻€乀omcat鐨勭紪鐮侀棶棰?/h2>Tomcat8鍜?鐨勭紪鐮佹柟寮?/h3>Tomcat7瀵筓RI榛樿缂栫爜鏄疘SO-8859-1 Tomcat8瀵筓RI榛樿缂栫爜鏄疷TF-8瀹樼綉瑙i噴锛?/div>URIEncoding 锛歍his specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.URIEncoding 锛歍his 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.鍦═omcat鍖呭唴涔熷彲浠ユ煡鎵惧埌锛?b>webapps鈫抎ocs鈫抍onfig鈫抙ttp.htmlURIEncoding 鍜寀seBodyEncodingForURI
浠omcat8涓轰緥锛?/div>锛?锛夈€乁RIEncodingThis 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.锛?锛夈€乽seBodyEncodingForURIThis 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鍙傛暟鍙互鏄鎵€鏈塆ET鏂瑰紡鐨勮姹傜殑鏁版嵁杩涜缁熶竴鐨勯噸鏂扮紪鐮侊紝榛樿缂栫爜涓?span> UTF-8锛?/span>璁剧疆useBodyEncodingForURI涓簍rue鏃讹紝璇锋眰鏌ヨ鍙傛暟鐨勭紪鐮佸拰contentType鐨勮缃竴鑷?/span>
涓夈€佽В鍐虫柟妗?/h2>1銆乁RIEncoding
<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
redirectPort="443" URIEncoding="UTF-8" />
x
1<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
2redirectPort="443" URIEncoding="UTF-8" />
URIEncoding鍙URL涓殑鍙傛暟杩涜缂栫爜2銆乽seBodyEncodingForURI="true"
璁剧疆useBodyEncodingForURI=true鏃讹紝灏变細灏嗚姹傚弬鏁板拰璇锋眰浣撲腑鐨勫弬鏁版牴鎹畆equest.setCharacterEncoding鎴栬€卌ontentType涓殑瀛楃闆嗙紪鐮併€?/div>3銆乺equest.setCharacterEncoding("UTF-8")
servlet绛塉ava鍚庡彴绋嬪簭涓娇鐢╮equest.setCharacterEncoding("UTF-8");request.setCharacterEncoding("UTF-8");杩欎釜鏂规硶瀵逛簬璇锋眰Body涓殑瀛楃缂栫爜鎵嶆湁浣滅敤,涔熷氨鏄熀鏈彧瀵筆OST浜х敓浣滅敤,缁堢┒鐨勫師鍥犳槸GET鏄疕TTP鏈嶅姟鍣ㄥ鐞嗭紝鑰孭OST鏄疻EB瀹瑰櫒澶勭悊4銆乪ncodingFilter
<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>
161<filter>
2 <filter-name>encodingFilter</filter-name>
3 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
4 <init-param>
5 <param-name>encoding</param-name>
6 <param-value>UTF-8</param-value>
7 </init-param>
8 <init-param>
9 <param-name>forceEncoding</param-name>
10 <param-value>true</param-value>
11 </init-param>
12 </filter>
13 <filter-mapping>
14 <filter-name>encodingFilter</filter-name>
15 <url-pattern>/*</url-pattern>
16 </filter-mapping>
5銆乼omcat7-maven-plugin鎻掍欢
<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>
x
1<plugin>
2 <groupId>org.apache.tomcat.maven</groupId>
3 <artifactId>tomcat7-maven-plugin</artifactId>
4 <version>2.1</version>
5 <configuration>
6 <port>9080</port>
7 <server>tomcat7</server>
8 <uriEncoding>UTF-8</uriEncoding>
9 </configuration>
10</plugin>
鍙傝€冭祫鏂欙細
1銆?a href="https://www.cnblogs.com/pangxiansheng/p/5679822.html">Tomcat7椤圭洰杩佺Щ鍒癟omcat8涓枃涔辩爜闂2銆?a href="https://www.cnblogs.com/yuanfy008/p/6937803.html#_labelTop">Java web涓父瑙佺紪鐮佷贡鐮侀棶棰橈紙涓€锛?/a>
Tomcat7瀵筓RI榛樿缂栫爜鏄疘SO-8859-1
Tomcat8瀵筓RI榛樿缂栫爜鏄疷TF-8
瀹樼綉瑙i噴锛?/div>
URIEncoding 锛歍his specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
URIEncoding 锛歍his 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.
鍦═omcat鍖呭唴涔熷彲浠ユ煡鎵惧埌锛?b>webapps鈫抎ocs鈫抍onfig鈫抙ttp.html
URIEncoding 鍜寀seBodyEncodingForURI
浠omcat8涓轰緥锛?/div>
涓夈€佽В鍐虫柟妗?/h2>
锛?锛夈€乁RIEncoding
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.
锛?锛夈€乽seBodyEncodingForURI
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鍙傛暟鍙互鏄鎵€鏈塆ET鏂瑰紡鐨勮姹傜殑鏁版嵁杩涜缁熶竴鐨勯噸鏂扮紪鐮侊紝榛樿缂栫爜涓?span> UTF-8锛?/span>
璁剧疆useBodyEncodingForURI涓簍rue鏃讹紝璇锋眰鏌ヨ鍙傛暟鐨勭紪鐮佸拰contentType鐨勮缃竴鑷?/span>
涓夈€佽В鍐虫柟妗?/h2>1銆乁RIEncoding
<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
redirectPort="443" URIEncoding="UTF-8" />
x
1<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
2redirectPort="443" URIEncoding="UTF-8" />
URIEncoding鍙URL涓殑鍙傛暟杩涜缂栫爜2銆乽seBodyEncodingForURI="true"
璁剧疆useBodyEncodingForURI=true鏃讹紝灏变細灏嗚姹傚弬鏁板拰璇锋眰浣撲腑鐨勫弬鏁版牴鎹畆equest.setCharacterEncoding鎴栬€卌ontentType涓殑瀛楃闆嗙紪鐮併€?/div>3銆乺equest.setCharacterEncoding("UTF-8")
servlet绛塉ava鍚庡彴绋嬪簭涓娇鐢╮equest.setCharacterEncoding("UTF-8");request.setCharacterEncoding("UTF-8");杩欎釜鏂规硶瀵逛簬璇锋眰Body涓殑瀛楃缂栫爜鎵嶆湁浣滅敤,涔熷氨鏄熀鏈彧瀵筆OST浜х敓浣滅敤,缁堢┒鐨勫師鍥犳槸GET鏄疕TTP鏈嶅姟鍣ㄥ鐞嗭紝鑰孭OST鏄疻EB瀹瑰櫒澶勭悊4銆乪ncodingFilter
<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>
161<filter>
2 <filter-name>encodingFilter</filter-name>
3 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
4 <init-param>
5 <param-name>encoding</param-name>
6 <param-value>UTF-8</param-value>
7 </init-param>
8 <init-param>
9 <param-name>forceEncoding</param-name>
10 <param-value>true</param-value>
11 </init-param>
12 </filter>
13 <filter-mapping>
14 <filter-name>encodingFilter</filter-name>
15 <url-pattern>/*</url-pattern>
16 </filter-mapping>
5銆乼omcat7-maven-plugin鎻掍欢
<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>
x
1<plugin>
2 <groupId>org.apache.tomcat.maven</groupId>
3 <artifactId>tomcat7-maven-plugin</artifactId>
4 <version>2.1</version>
5 <configuration>
6 <port>9080</port>
7 <server>tomcat7</server>
8 <uriEncoding>UTF-8</uriEncoding>
9 </configuration>
10</plugin>
鍙傝€冭祫鏂欙細
1銆?a href="https://www.cnblogs.com/pangxiansheng/p/5679822.html">Tomcat7椤圭洰杩佺Щ鍒癟omcat8涓枃涔辩爜闂2銆?a href="https://www.cnblogs.com/yuanfy008/p/6937803.html#_labelTop">Java web涓父瑙佺紪鐮佷贡鐮侀棶棰橈紙涓€锛?/a>
<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
redirectPort="443" URIEncoding="UTF-8" />
x
1
<Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1"
2
redirectPort="443" URIEncoding="UTF-8" />
3銆乺equest.setCharacterEncoding("UTF-8")
servlet绛塉ava鍚庡彴绋嬪簭涓娇鐢╮equest.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");杩欎釜鏂规硶瀵逛簬璇锋眰Body涓殑瀛楃缂栫爜鎵嶆湁浣滅敤,涔熷氨鏄熀鏈彧瀵筆OST浜х敓浣滅敤,缁堢┒鐨勫師鍥犳槸GET鏄疕TTP鏈嶅姟鍣ㄥ鐞嗭紝鑰孭OST鏄疻EB瀹瑰櫒澶勭悊
4銆乪ncodingFilter
<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>
16
1
<filter>
2
<filter-name>encodingFilter</filter-name>
3
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
4
<init-param>
5
<param-name>encoding</param-name>
6
<param-value>UTF-8</param-value>
7
</init-param>
8
<init-param>
9
<param-name>forceEncoding</param-name>
10
<param-value>true</param-value>
11
</init-param>
12
</filter>
13
<filter-mapping>
14
<filter-name>encodingFilter</filter-name>
15
<url-pattern>/*</url-pattern>
16
</filter-mapping>
5銆乼omcat7-maven-plugin鎻掍欢
<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>
x
1
<plugin>
2
<groupId>org.apache.tomcat.maven</groupId>
3
<artifactId>tomcat7-maven-plugin</artifactId>
4
<version>2.1</version>
5
<configuration>
6
<port>9080</port>
7
<server>tomcat7</server>
8
<uriEncoding>UTF-8</uriEncoding>
9
</configuration>
10
</plugin>
鍙傝€冭祫鏂欙細
1銆?a href="https://www.cnblogs.com/pangxiansheng/p/5679822.html">Tomcat7椤圭洰杩佺Щ鍒癟omcat8涓枃涔辩爜闂
2銆?a href="https://www.cnblogs.com/yuanfy008/p/6937803.html#_labelTop">Java web涓父瑙佺紪鐮佷贡鐮侀棶棰橈紙涓€锛?/a>
以上是关于JavaWeb涓亣鍒扮殑瀛楃缂栫爜闂的主要内容,如果未能解决你的问题,请参考以下文章