剛開始接觸jsp,比較偏向於用button標簽的onclick方法進行頁面的跳轉。但是關於頁面跳轉的各種問題真是叫人頭大,以下記錄,僅僅為自己以后查看。
Qone 用url傳參的時候遇到中文怎么辦
編碼再解碼:傳輸時用encodeURI進行編碼,獲取參數時URLEncoder.encode進行解碼;
頁面1:
function sub(){ var content1 = document.getElementById("tn"); var content2 = document.getElementById("ln"); alert(content1.value); alert(content2.value); window.location.href="value.jsp?"+"tn="+encodeURI(content1.value)+"&ln="+encodeURI(content2.value); }
頁面2:
在定義get方法時,進行解碼
public String get_url_Name() throws UnsupportedEncodingException { String encodedname = URLEncoder.encode(name, "UTF-8"); return encodedname; }
Qtwo:url傳輸多個參數時到底該怎么寫
href="下一頁面.jsp?"+參數+“&參數名”+參數值
加號不能少,不然頁面跳轉就會失敗
ps:這種明傳址的方法不安全,但是暫時不會別的方法,將就用吧,有時間回看。