日期:2014-05-16  浏览次数:20408 次

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

转自:http://blog.csdn.net/fei1502816/article/details/7227396

?

JSP页面,通过JS的location.url跳转

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

网上搜所,解决方案如下

1.页面编码

?

[javascript] view plaincopyprint?
  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. ????????}??
//导出
		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解码

?

[java] view plaincopyprint?
  1. String?word="页面传过来的中文参数"??
  2. String?temp?=?new?String(keyword.getBytes("ISO-8859-1"),"utf-8");??
  3. keyword?=?URLDecoder.decode(temp,?"utf-8");??