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.html

URIEncoding 鍜寀seBodyEncodingForURI

浠omcat8涓轰緥锛?/div>
锛?锛夈€乁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" />
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>

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>

鍙傝€冭祫鏂欙細

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涓亣鍒扮殑瀛楃缂栫爜闂的主要内容,如果未能解决你的问题,请参考以下文章

浜岃繘鍒?amp;瀛楃缂栫爜_20210306

1760澶氬厓Huffman缂栫爜闂锛堣椽蹇冿級

浠€涔堟槸async鍜宎wait?(椤圭洰涓亣鍒扮殑)

瀛楃缂栫爜-ASCII锛孶nicode 鍜?UTF-8

flask_migrate鏁版嵁搴撹縼绉婚亣鍒扮殑闂

瀛楄妭璺冲姩鏈€甯歌€冪殑 64 閬揓S绠楁硶棰?/a>