下面的代碼我相信大家可能都會遇到:
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");
這樣就可以解決了。