关于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");

这样就可以解决了。

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