SpringMvc參數傳遞中亂碼問題


問題描述:

當傳遞中文參數到controller類時,無亂是get方式還是post方式都出現亂碼

解決:

1、保證所有的頁面編碼都是utf-8,包括jsp頁面,瀏覽器編碼設置和eclipse的編碼設置。

2、spingmvc給我們提供了一個編碼過濾器,只需要在配置文件web.xml中加入即可。如下:

 1 <filter>
 2       <filter-name>characterEncoding</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   </filter>
 9   <filter-mapping>
10       <filter-name>characterEncoding</filter-name>
11       <url-pattern>/*</url-pattern>
12   </filter-mapping>
View Code

3、以上兩步有時只能解決post方式傳遞參數亂碼問題,get方式還是出現亂碼,則就需要該tomcat的配置文件了,打開tomcat的server.xml文件,找到以下行

1 <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
View Code

在上面行中插入URIEncoding="UTF-8",改成如下形式:

1 <Connector URIEncoding="UTF-8"  connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
View Code

這樣就解決了springmvc中文參數傳遞亂碼問題了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM