利用url傳多個參數


剛開始接觸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:這種明傳址的方法不安全,但是暫時不會別的方法,將就用吧,有時間回看。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM