传中文查询乱码问题 则需要对要传的参数进行二次编码

例如  window.location.href ="/xx.jsp?name="+name+""; 

这样子则会乱码

改成

window.location.href ="/xx.jsp?name="+  encodeURI(encodeURI(name))+""; 

 

在接受的jsp页面 或者是controller 中进行解码

String name = java.net.URLDecoder.decode(request.getParameter("name"), "utf-8");

 在js中解码的话是这样的,


var dataName = decodeURI(GetQueryString("name"), "utf-8");

这样子即解决在用 window.location.href  传中文的乱码问题

 

这里写到了个取url中参数的函数顺便记录下!

function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}

相关文章:

  • 2022-12-23
  • 2021-06-07
  • 2021-08-17
  • 2021-11-01
  • 2021-10-06
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-02-11
相关资源
相似解决方案