Tomcat項目get請求中參數亂碼問題

在項目中遇到了使用get請求發送參數的時候在後臺獲取到數據是中文亂碼,我首先想到的是沒有配置比編碼過濾器,可是檢查過項目以後已經配置好了編碼過濾器,對全部的url請求已經使用了utf-8的編碼過濾器。 後來纔想起來是tomcat編碼配置問題。 修改tomcat的配置文件service.xmlhtml

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="utf-8" />

添加URIEncoding="utf-8"。解決get中文亂碼問題。 咱們再來引伸一下tomcat其餘參數的配置,難道你不想知道爲何能夠這樣配置嗎,還有些什麼配置參數能夠配置的呢,看一下配置文件上面的這段註釋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.url

你看,若是沒配置的話默認是使用ISO-8859-1編碼,咱們項目是用utf-8de,因此就亂碼了嘛。 等我有空的時候再看看其餘有沒有什麼有用的參數。鑑於時間關係和英文水平有限,暫時就到這裏code

相關文章
相關標籤/搜索