在js中通過location.href方式跳轉頁面並在路徑上傳遞參數中文亂碼解決


js中對中文進行編碼:(不對ASCII 字母和數字進行編碼)
window.document.location.href = "${ctxPath}/pc/selectDTByXinFang/html?subWayName="+encodeURI(encodeURI(subWayName))+"&dtId=" + dtId;
//有時只需要編碼一次即可(具體原因沒有細究)
window.document.location.href = "${ctxPath}/pc/selectDTByXinFang/html?subWayName="+encodeURI(subWayName)+"&dtId=" + dtId;
在action中獲取時需要通過URLDecoder.decode(name, "UTF-8");方式進行解碼即可.
//中文解碼
try {
stationName = URLDecoder.decode(stationName, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}



------------------------------------------------------------------------------------
js中對中文進行編碼:(對ASCII 字母和數字進行編碼)
window.document.location.href = "${ctxPath}/pc/selectDTByXinFang/html?subWayName="+encodeURIComponent(encodeURIComponent(subWayName))+"&dtId=" + dtId;
//中文解碼
try {
blockName = new String(blockName.getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM