關於javascript URL 傳遞參數亂碼的問題及解決方案。

下面的代碼我相信大家可能都會遇到:

window.location.href="/suisitu/suser/user_insert?userCode="+usercode+"&username="+username+"&changeuser="+ChangUser+"&changedate="+ChangDate; 
這樣傳遞參數的方式獲取比較愚蠢。但是如果不得已爲之那怎麼解決呢?
解決辦法是:
window.location.href=encodeURI(encodeURI("/suisitu/suser/user_insert?userCode="+usercode+"&username="+username+"&changeuser="+ChangUser+"&changedate="+ChangDate)); 

而在java的頁面端則使用:

URLDecoder.decode(username, "utf-8");

這樣就可以解決了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章