js url传值中文乱码之解决之道_javascript技巧

时间:2022-04-18 20:11:36
url=encodeURI(encodeURI(url)); //用了2次encodeURI 测试成功,第一次转换没有尝试, 
处理方法一。 
js 程序代码:url=encodeURI(url);注意是整个URL 
服务器端的代码:String linename = new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8"); 
处理方法二。 
js:var url="name="+name; 
url=encodeURI(encodeURI(url)); //用了2次encodeURI 
window.location = "<%=path%>/inner/line/line.jsp?"+url; 
服务器端的代码: 
String linename = request.getParameter(name); 
//java : 字符解码 
linename = java.net.URLDecoder.decode(linename , "UTF-8");