在jsp頁面如何獲得url參數(shù)
更新時(shí)間:2014年02月18日 16:45:05 作者:
這篇文章主要介紹了在jsp頁面獲得url參數(shù)的方法,需要的朋友可以參考下
當(dāng)一個(gè)url過來時(shí),如: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得到
%>
然后在<body>hello:<%=name%></body>中顯示。
也可以在body中直接用${}得到,因?yàn)楫?dāng)使用jstl時(shí),url請(qǐng)求參數(shù)被放置到隱含對(duì)象param中。所以可以這樣寫:
<body>hello:${param.name}</body>
依據(jù)此邏輯,在使用jquery時(shí),也可以用同樣的方法得到,如:
$(function(){
alert(${param.name});
});
復(fù)制代碼 代碼如下:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String name = request.getParameter("name");//用request得到
%>
然后在<body>hello:<%=name%></body>中顯示。
也可以在body中直接用${}得到,因?yàn)楫?dāng)使用jstl時(shí),url請(qǐng)求參數(shù)被放置到隱含對(duì)象param中。所以可以這樣寫:
復(fù)制代碼 代碼如下:
<body>hello:${param.name}</body>
依據(jù)此邏輯,在使用jquery時(shí),也可以用同樣的方法得到,如:
$(function(){
alert(${param.name});
});
相關(guān)文章
JSP中常用的JSTL fmt(format格式化)標(biāo)簽用法整理
這篇文章主要介紹了JSP中常用的JSTL fmt(format格式化)標(biāo)簽用法整理,fmt的格式化處理遵循i18n國(guó)際化格式標(biāo)準(zhǔn),需要的朋友可以參考下2016-04-04
Java Web實(shí)現(xiàn)的基本MVC實(shí)例分析
這篇文章主要介紹了Java Web實(shí)現(xiàn)的基本MVC,以完整實(shí)例形式較為詳細(xì)的分析了JSP實(shí)現(xiàn)MVC架構(gòu)的具體步驟與相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09

