关于URL或JS中的URL传参中文乱码问题

来源:互联网 发布:男友尺寸知乎 编辑:程序博客网 时间:2024/06/05 07:25

 iLife's 博客http://blog.csdn.net/fei1502816 





有一个页面,通过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");  

0 0
原创粉丝点击