js解决中文乱码传值问题

今天在代码中遇到url传中文名的参数值过去.到后台request接收的时候直接乱码了.

解决办法1.

 前端
  function goToFundrecordInit(userId,username){
   var newUserName = encodeURI(encodeURI(username)); //这里encodeURI 两次
   alert("newUserName:"+newUserName);
   var url = "queryUserFundrecordInit.do?userId="+userId+"&userName="+newUserName;
   window.location.href = url;
  }

 

后端

  String str = request("userName");//这里request封装过.
  String userName =  URLDecoder.decode(str,"utf-8");

  Sysout.out.println(userName);

搞定.

你可能感兴趣的:(javaScript)