1. 程式人生 > >Extjs4.2 ajax請求url中傳中文參數亂碼問題

Extjs4.2 ajax請求url中傳中文參數亂碼問題

post func cti art utf-8 getpara parameter load() 中文

今天有個需求須要在url中傳入中文參數。結果在後臺取得時出現亂碼,懷疑可能是編碼問題。上網查詢了資料,試了幾種辦法。發現有一種可行,記錄在此,以便查閱。

url中用encodeURI 進行2次編碼:

Ext.Ajax.request({
	url:"updateadminuser.do?"+userid+"&uname="+encodeURI(encodeURI(uname)), 
	success:function (response) {
		store.load();
	}
});

然後在servlet中進行解碼:

String uname = java.net.URLDecoder.decode(request.getParameter("uname"), "UTF-8");


就可以!

Extjs4.2 ajax請求url中傳中文參數亂碼問題