`

js url传参中文乱码解决方案

阅读更多

今天发现一个问题

有一个页面,通过JS的location.url跳转

中间传了几个条件参数,但这个参数是中文的时候,就出现了乱码问题

网上搜所,解决方案如下

1.页面编码

 

  1. //导出  
  2.         function exportExcel(){  
  3.             var projectName_e = document.getElementById("pname").value;   
  4.             var unitName = document.getElementById("unitName").value;             
  5.             var projectState = document.getElementById("projectState").value;     
  6.             var lyear = document.getElementById("lxYear").value;                  
  7.             var str = "projectName_e="+encodeURIComponent(projectName_e)+"&unitName="+encodeURIComponent(unitName)+"&lyear="+lyear  
  8.             window.location="<%=basePath%>/mproject/project_getAllProjectList.action?"+str+"&flag=1&projectType=${projectType}";  
  9.         }  

2.Action解码

 

  1. String word="页面传过来的中文参数"  
  2. String temp = new String(keyword.getBytes("ISO-8859-1"),"utf-8");  
  3. keyword = URLDecoder.decode(temp, "utf-8");  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics