本文实例讲述了JS传值出现中文参数乱码的解决方法。分享给大家供大家参考,具体如下:
function PopupFK(cNum,type){
var url = "contract!Paying.action";
url = url + "?contract.contractNum="+cNum+"&payingType="+type;
// if(isEmpty($(_this).attr("payId"))){
// url = url + "&s_paymentId="+paymentId;
// url = url + "&s_paymentDtlId="+paymentDtlId;
// }else{
// url = url + "&s_payId="+$(_this).attr("payId");
// }
url = url+"&random="+Math.random();
//在这里。用encodeURI进行两次转码。后台Action接收的时候。在进行一次。就不会出现乱码问题
url = encodeURI(url);
url = encodeURI(url);
var ret = window.showModalDialog(
url,
"",
"dialogWidth=950px;dialogHeight=600px;center=yes;border=thick;status=no;help=no;scrollbars=no"
);
}
下面是Action代码片段
String cNum = contract.getContractNum();
String Num;
try {
Num = URLDecoder.decode(cNum,"utf8");
System.out.println(Num);
c = csl.queryOneByNum(Num);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("合同数据错误,请联系管理员");
}
希望本文所述对大家JavaScript程序设计有所帮助。