jsp頁面向後臺傳值出現亂碼的問題

今天做普通的前臺頁面向後臺傳值,要傳值的內容是中文,傳到後臺打印一看 居然內容變成了 “?????”

於是在網上找了一些方法  :

1、採用decode()方法

 頁面:

[html] view plaincopy
  1. Url: '<%=path%>/sfyh/infodata.jsp?type='+encodeURI(ss)  

,


  後臺:

[html] view plaincopy
  1. String result = java.net.URLDecoder.decode(type,"UTF-8")  

2、採用設置字符集的方式
[html] view plaincopy
  1. request.setCharacterEncoding("utf-8")  


3、在頁面上定義charset的字符集(最有效 最簡單

[html] view plaincopy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"    
  2.         pageEncoding="utf-8"%>    
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  

 

4、採用轉碼的方式

頁面:

[html] view plaincopy
  1. Url: '<%=path%>/sfyh/infodata.jsp?type='+encodeURIComponent(ss)  



後臺:
[html] view plaincopy
  1. resultnew String(request.getParameter("type").getBytes("ISO8859-1"),"UTF-8")  


暫時就寫到這吧
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章