a連結傳輸中文,頁面和後臺處理方式
阿新 • • 發佈:2019-01-11
頁面之間用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