jsp文件:webiURL = "openDocument.jsp?" +
"iDocID=" + iDocID +"&token=" + token+"&user="+user+"&path="+docPath;
response.sendRedirect(webiURL);docPath是中文内容接受是js:var user =getUser(window.parent.location.search);
alert(encodeURI(window.parent.location.search));alert提示的path内容是乱码:path=QGR01s.%2507%2507%25C5%25B5
很郁闷
"iDocID=" + iDocID +"&token=" + token+"&user="+user+"&path="+docPath;
response.sendRedirect(webiURL);docPath是中文内容接受是js:var user =getUser(window.parent.location.search);
alert(encodeURI(window.parent.location.search));alert提示的path内容是乱码:path=QGR01s.%2507%2507%25C5%25B5
很郁闷
用表单的SUBMIT();
或是window.location = url;
var s=unescape(encodeURI(window.parent.location.search).replace(/\\\\u/g,'%u'));
alert(s)
这个方法不行 还是乱码
看来在URL里显示中文 比较的不容易啊
先解码,再还原
另外在接受的一方处理的时候也要转换
不知道你用的是什么 我用的是java 在action里处理的时候
response.setContentType("text/xml");
response.setCharacterEncoding("utf-8");
List list = site.getCity(new String(((String)request.getParameter("pro")).getBytes("ISO-8859-1"),"utf-8"));
encodeURIComponent--decodeURIComponent
encodeURI--decodeURI
escape--unescape
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
试试
"iDocID=" + iDocID +"&token=" + token+"&user="+user+"&path="+docPath;
将所有参数用escape先转化为16进制,再将参数用encodeURI编码
结果页面再使用unescape使其可读
具体如下:
webiURL = "openDocument.jsp?" +
"iDocID=" + encodeURI(escape(iDocID)) +"&token=" + encodeURI(escape(token))+"&user="+encodeURI(escape(user))+"&path="+encodeURI(escape(docPath));
试试,做项目时遇到过,就这样处理可以了,不知道楼主这样用可不可以
为了方便 JavaScript 读取,你还要使用 UTF-8 字符集.import java.net.URLEncoder;public String uri(key, value) {
return java.net.URLEncoder.encode(key,"UTF-8")+"="+java.net.URLEncoder.encode(value, "UTF-8") + "&";
}webiURL = "openDocument.jsp?" + uri("iDocID", iDocID) + uri("token", token) +
uri("user", user) + uri("path", path);
response.sendRedirect(webiURL);// js 读取
function getRequest(key) {
var regex = new RegExp("[?&]" + encodeURIComponent(key) + "\\=([^&#]+)");
var value = (location.search.match(regex)||["",""])[1];
return decodeURIComponent(value);
}
var path = getRequest("path");
alert(path);
经过验证的,ie,火狐,谷歌都行