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

来源:互联网 发布:ubuntu直接安装deb 编辑:程序博客网 时间:2024/06/15 18:29

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


今天发现一个问题

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

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

网上搜所,解决方案如下

1.页面编码

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

2.Action解码

String word="页面传过来的中文参数"String temp = new String(keyword.getBytes("ISO-8859-1"),"utf-8");keyword = URLDecoder.decode(temp, "utf-8");



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