Parameters from the URL with JSP

  • Beitrags-Autor:
  • Beitrags-Kategorie:Java

About the Implicit Objects of the Unified Expression Language, the Java EE 5 Tutorial writes:

  • The pageContext 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 value
    • paramValues: Maps a request parameter name to an array of values
    • header: Maps a request header name to a single value
    • headerValues: Maps a request header name to an array of values
    • cookie: Maps a cookie name to a single cookie
    • initParam: 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 values
    • requestScope: Maps request-scoped variable names to their values
    • sessionScope: Maps session-scoped variable names to their values
    • applicationScope: Maps application-scoped variable names to their values
${param.abc}
<c:out value="${param.abc}"></c:out>
<c:out value="${param['abc']}"></c:out>
<%= request.getParameter("abc") %>
<%
    String abc = request.getParameter("abc");
    if (abc == null) {
        out.println("???");
    } else {
        out.println(abc);
    }
%>

 
 
 

copied from stackoverflow.com

Parameter weitergeben…

<c:set var="abc" value="${abc}" scope="session"/>
<c:out value="${sessionScope.abc}"/>
<c:set var="abc" value="${empty param.abc ? sessionScope.abc : param.abc}"/>