在jsp頁面如何獲得url引數

2021-08-11 14:53:33 字數 551 閱讀 6984

當乙個url過來時,如:http://localhost:8080/pro/demo/hello.jsp?name=john,在hello.jsp頁面,我們可以這樣得到name的值:

<%

string path = request.getcontextpath();

string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";

string name = request.getparameter("name");//用request得到

%>

然後在hello:<%=name%>中顯示。

也可以在body中直接用${}得到,因為當使用jstl時,url請求引數被放置到隱含物件param中。所以可以這樣寫:

hello:$

依據此邏輯,在使用jquery時,也可以用同樣的方法得到,如:

$(function());

});

在jsp頁面如何獲得url引數

方法一 當乙個url過來時,如 http localhost 8080 pro demo hello.jsp?name john,在hello.jsp頁面,我們可以這樣得到name的值 string path request.getcontextpath string basepath reques...

在jsp頁面如何獲得url引數

當乙個url過來時,如 http localhost 8080 pro dem程式設計客棧o hello.jsp?name john,在hello.jsp頁面,我們可以這樣得到程式設計客棧name的值 複製 如下 string p程式設計客棧ath程式設計客棧 request.getcontextp...

在頁面獲取在url後面的引數

跳轉到login.jsp頁面的鏈結 var url window.location.href 獲取當前頁面的鏈結 window.location.href login.jsp?url encodeuricomponent url 傳遞的時候,帶位址傳遞過去 在login.jsp頁面 把uri獲取到,...