Thursday, April 28, 2011

jsp:forward

<jsp:forward/>
JSP provide an equivalent to the RequestDispather.forward() method by use of
the forward action. The forward action forwards a request to a new resource and
clears any content that might have previously been sent to the output buffer by
the current JSP. Should the current JSP not be buffered, or the contents of the
buffer already be sent to a client, an IllegalStateException is thrown.
The
forward action uses the following syntax: <jsp:forward url="relativeURL"/>,
where the value of relativeURL is the relative location in the current Web
Application of the resource to forward the request to. Optionally the forward
action may have param actions used as subelements to define request parameters.
Where applicable, the param action values override existing request parameters.

<jsp:forward/> and <jsp:include/> parameters

Both the JSP forward and includes actions can optionally include parameters.
The mechanism for doing this is the JSP param action. The param action may only
appear in the body of either the forward or include actions and is used to define
parameters. The syntax of the param action is as follows:
<jsp:param name="parameter's name" value="parameter's value"/>
The parameter is a key/value pair with the name attribute specifying the name
and value attribute specifying the value.The values are made available to the for-
warded or included resource via the HttpServletRequest getParameter()
method, for instance, if the forward action was authored as the following:
<jsp:forward page="examplePage.jsp">
<jsp:param name="foo1" value="bar"/>
<jsp:param name="foo2" value="<%= foo %>"/>
</jsp:forward>
The fictitious page examplePage.jsp would have two additional request
parameters set for it: foo1 and  foo2. The value of foo1 would be ‘bar’ and the
value of foo2 would be the string representation of whatever the foo variable
was.In the case where a parameter specified by the param action conflicts with an
existing parameter, the existing parameter is replaced.

No comments:

Post a Comment