在前台页面编码两次:
?url=encodeURI(url);
?url=encodeURI(url);
?
举个例子
usid为要传递到servlet的中文参数
var usid = encodeURI(sid);//uri编码
usid=encodeURI(usid);//再次uri编码
var url = "selectNameServlet?sid=" +usid;//合并构造url
if (window.XMLHttpRequest) {
?? ? ?req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
?? ? ?req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
?? ? req.open("GET", url, true);
?? ? req.onreadystatechange = complete;
?? ? req.send(null);
}
else
{
?? ? alert("fail to create request");
}
}
在服务器端对中文参数解码:
String sid = request.getParameter("sid");
String usid = URLDecoder.decode(sid, "utf-8");
?