The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.servlet.jsp  [18 examples] > Java Server Pages Input  [4 examples]

e1055. Passing Parameters to Another JSP Page

An include action (see e1054 Including a File in a JSP Page) executes the included JSP page and appends the generated output onto its own output stream. Request parameters parsed from the URL's query string are available not only to the main JSP page but to all included JSP pages as well. It is possible to temporarily override a request parameter or to temporarily introduce a new request parameter when calling a JSP page. This is done by using the jsp:param action.

In this example, param1 is specified in the query string and is automatically made available to the callee JSP page. param2 is also specified in the query string but is overridden by the caller. Notice that param2 reverts to its original value after the call. param3 is a new request parameter created by the caller. Notice that param3 is only available to the callee and when the callee returns, param3 no longer exists. Here is the caller JSP page:

    <html>
    <head></head>
    <body>
    
    <jsp:include page="callee.jsp" />
        <jsp:param name="param2" value="value2" />
        <jsp:param name="param3" value="value3" />
    </jsp:include>
    
    Caller:
    param1: <%= request.getParameter("param1") %>
    param2: <%= request.getParameter("param2") %>
    param3: <%= request.getParameter("param3") %>
    
    </body>
    </html>
Here is the JSP page being called:
    Callee:
    param1: <%= request.getParameter("param1") %>
    param2: <%= request.getParameter("param2") %>
    param3: <%= request.getParameter("param3") %>
If the example is called with the URL:
    http://hostname.com?param1=a&param2=b
the output would be:
    Callee:
    param1: a
    param2: value2
    param3: value3
    
    
    Caller:
    param1: a
    param2: b
    param3: null

 Related Examples
e1053. Getting a Request Parameter in a JSP Page
e1054. Including a File in a JSP Page
e1056. Using a Bean in a JSP Page

See also: Java Server Pages    Java Server Pages Headers    Java Server Pages Output   


© 2002 Addison-Wesley.