In JSP how do I get parameters from the URL?
For example I have a URL www.somesite.com/Transaction_List.jsp?accountID=5
I want to get the 5.
Is there a request.getAttribute( "accountID" ) like there is for sessions or something similar?
About the Implicit Objects of the Unified Expression Language, the Java EE 5 Tutorial writes:
Implicit Objects
The JSP expression language defines a set of implicit objects:
pageContext
: The context for the JSP page. Provides access to various objects including:
servletContext
: The context for the JSP page’s servlet and any web components contained in the same application. See Accessing the Web Context.session
: The session object for the client. See Maintaining Client State.request
: The request triggering the execution of the JSP page. See Getting Information from Requests.response
: The response returned by the JSP page. See Constructing Responses.- In addition, several implicit objects are available that allow easy access to the following objects:
param
: Maps a request parameter name to a single valueparamValues
: Maps a request parameter name to an array of valuesheader
: Maps a request header name to a single valueheaderValues
: Maps a request header name to an array of valuescookie
: Maps a cookie name to a single cookieinitParam
: Maps a context initialization parameter name to a single value- Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.
pageScope
: Maps page-scoped variable names to their valuesrequestScope
: Maps request-scoped variable names to their valuessessionScope
: Maps session-scoped variable names to their valuesapplicationScope
: Maps application-scoped variable names to their values
The interesting parts are in bold :)
So, to answer your question, you should be able to access it like this (using EL):
${param.accountID}
Or, using JSP Scriptlets (not recommended):
<%
String accountId = request.getParameter("accountID");
%>