页面之间用a链接传递中文参数问题
<a type='button' class='button border-main' href='" + encodeURI("addmanage.jsp?id="+obj.coname) + "'><span class='icon-edit'></span>派货</a>
在使用页面用encodeURI对链接进行编码
/*拿到前台传过来的id*/
hreftext = window.location.href;
console.log(hreftext)
beginIndex = hreftext.indexOf("?");
hreftext = decodeURI(hreftext.slice(beginIndex+4,hreftext.length))
console.log(hreftext)
document.getElementById('unname').value=hreftext;/*必须保证id在前面定义,否则找不到*/
接收页面使用decodeURI进行解码,就可以解决中文乱码问题了
后台servlet接收a链接中文
String coname=new String((request.getParameter("coname").getBytes("ISO-8859-1")),"gb2312");
如果还是乱码请把编码换一下,把gb2312换成utf-8