background image

Transferring Control to Another Web Component

<< Reusing Content in JSP Pages | Including an Applet >>
<< Reusing Content in JSP Pages | Including an Applet >>

Transferring Control to Another Web Component

Transferring Control to Another Web Component
The mechanism for transferring control to another web component from a JSP page uses the
functionality provided by the Java Servlet API as described in
"Accessing a Session" on
page 125
. You access this functionality from a JSP page by using the jsp:forward element:
<jsp:forward page=
"/main.jsp" />
Note that if any data has already been returned to a client, the jsp:forward element will fail
with an IllegalStateException.
jsp:param
Element
When an include or forward element is invoked, the original request object is provided to the
target page. If you wish to provide additional data to that page, you can append parameters to
the request object by using the jsp:param element:
<jsp:include page=
"..." >
<jsp:param name=
"param1" value="value1"/>
</jsp:include>
When jsp:include or jsp:forward is executed, the included page or forwarded page will see
the original request object, with the original parameters augmented with the new parameters
and new values taking precedence over existing values when applicable. For example, if the
request has a parameter A=foo and a parameter A=bar is specified for forward, the forwarded
request will have A=bar,foo. Note that the new parameter has precedence.
The scope of the new parameters is the jsp:include or jsp:forward call; that is, in the case of
an jsp:include the new parameters (and values) will not apply after the include.
Including an Applet
You can include an applet or a JavaBeans component in a JSP page by using the jsp:plugin
element. This element generates HTML that contains the appropriate
client-browser-dependent construct (<object> or <embed>) that will result in the download of
the Java Plug-in software (if required) and the client-side component, and in the subsequent
execution of any client-side component. The syntax for the jsp:plugin element is as follows:
<jsp:plugin
type=
"bean|applet"
code=
"objectCode"
codebase=
"objectCodebase"
{ align=
"alignment" }
Transferring Control to Another Web Component
The Java EE 5 Tutorial · September 2007
176