js url 傳遞參數時中文亂碼問題解決

 
方案一

html頁面:

function testOne() {

   var url =  "testTwo.action?expr="+你好;

   window.location.href = encodeURI(url);

}

後臺java代碼:

String expr = new String(request.getParameter("expr").getBytes("ISO-8859-1"),"UTF-8");  

方案二

html頁面:

function testTwo() {

  var url =  "testTwo.action?expr="+你好;

  window.location.href= encodeURI(encodeURI(url)); 

}

後臺java代碼:

String expr

=java.net.URLDecoder.decode(lrequest.getParameter("expr") , "UTF-8");

方案三

html頁面:

function testTwo() {

  var url =  "testTwo.action?expr="+你好;

  window.location.href= encodeURI(encodeURI(url)); 

}

後臺java代碼:

 string name =HttpUtility.UrlDecode(Request.QueryString["name"].ToString());

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