tomcat 7+ IE瀏覽器中文傳引數亂碼
阿新 • • 發佈:2018-12-06
方法1:
Tomcat\conf\server.xml,指定瀏覽器的編碼格式為“UTF-8”:
<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding='UTF-8' />
方法2
Tomcat\conf\web.xml,檢視型別為htm/html的設定,將其編碼集設為UTF-8
<mime-mapping>
<extension> htm </extension>
<mime-type>text/html; charset=UTF-8 </mime-type>
</mime-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html; charset=UTF-8</mime-type>
</mime-mapping>
方法3
在啟動start.sh指令碼中新增一句
export LANG=zh_CN.UTF-8
方法4
將跳轉連結放在頁面的節點中,用window.open跳轉
方法5
使用javascript的encodeURI()編碼,使用java的URLDecoder.decode(value, “UTF-8”)解碼
備註
javascript:
-
escape()不能直接用於URL編碼,它的真正作用是返回一個字元的Unicode編碼值。比如"春節"的返回結果是%u6625%u8282,,escape()不對"+"編碼 主要用於漢字編碼,現在已經不提倡使用。
-
encodeURI()是Javascript中真正用來對URL編碼的函式。 編碼整個url地址,但對特殊含義的符號"; / ? : @ & = + $ , #",也不進行編碼。對應的解碼函式是:decodeURI()。
-
encodeURIComponent() 能編碼"; / ? : @ & = + $ , #"這些特殊字元。對應的解碼函式是decodeURIComponent()。
java:
- URLDecoder.decode(value, “UTF-8”); 解碼函式
- URLEncoder.encode(value, “UTF-8”); 編碼函式
方法6
web.xml中加入spring處理中文的
<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>
方法7
name=new String(name.trim().getBytes("ISO-8859-1"), "UTF-8");