js window.open将参数传递到struts中出现的乱码问题解决

在页面的时候首先要对传递到后台的参数进行编码一些

path=encodeURI(encodeURI(path));

fileName=encodeURI(encodeURI(fileName));

注意如果使用一个encodeURI()的话在后台接收到的就是????号写两个就是%4%3%3这种的

window.open(url+"?path="+path+"?fileName="+fileName);

到后台接受参数后

String path=ServletActionContext.getRequest().getParameter("path").toString();
  String fileName=ServletActionContext.getRequest().getParameter("fileName").toString();
 

在次进行转码:

  path=java.net.URLDecoder.decode(path,"UTF-8");
  fileName=java.net.URLDecoder.decode(fileName,"UTF-8");

现在就没有乱码了!

你可能感兴趣的:(js,乱码,window.open乱码,struts2接收参数乱码)