Tomcat解决HTTP GET中文乱码
生活随笔
收集整理的這篇文章主要介紹了
Tomcat解决HTTP GET中文乱码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、中文亂碼原因
Tomcat默認是按ISO-8859-1進行URL解碼,ISO-8859-1并未包括中文字符,中文字符不能被正確解析了。
?
二、配置編碼
在tomcat的conf/server.xml下的connetor屬性中增加URIEncoding或者useBodyEncodingForURI屬性
(1)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.
譯文:這指定了用于解碼URI字節的字符編碼。如果沒有指定,將使用ISO-8859-1。
?如:
<Server port="8005" shutdown="SHUTDOWN"><!-- 其他配置 --><Service name="Catalina"><Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" /> <!-- 其他配置 --></Service> </Server>?
(2)useBodyEncodingForURI
This specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding.
譯文:這指定編碼指定contentType應使用URI查詢參數,而不是使用URIEncoding。
如:
<Server port="8005" shutdown="SHUTDOWN"><!-- 其他配置 --><Service name="Catalina"><Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" /> <!-- 其他配置 --></Service> </Server>?
總結
以上是生活随笔為你收集整理的Tomcat解决HTTP GET中文乱码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 100元左右机顶盒推荐?
- 下一篇: 刚出生10天的小狗,母狗死了,应该怎么样