10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Transferring Control to AnotherWeb Component<br />

Because you must put an include directive in each file that reuses the resource referenced by<br />

the directive, this approach has its limitations. Preludes and codas can be applied only to the<br />

beginnings and ends of pages. For a more flexible approach to building pages out of content<br />

chunks, see “A Template Tag Library” on page 264.<br />

<strong>The</strong> jsp:include element is processed when a JSP page is executed. <strong>The</strong> include action allows<br />

you to include either a static or a dynamic resource in a JSP file. <strong>The</strong> results of including static<br />

and dynamic resources are quite different. If the resource is static, its content is inserted into the<br />

calling JSP file. If the resource is dynamic, the request is sent to the included resource, the<br />

included page is executed, and then the result is included in the response from the calling JSP<br />

page. <strong>The</strong> syntax for the jsp:include element is:<br />

<br />

<strong>The</strong> hello1 application discussed in “Packaging Web Modules” on page 83 uses the following<br />

statement to include the page that generates the response:<br />

<br />

Transferring Control to AnotherWeb Component<br />

174<br />

<strong>The</strong> mechanism for transferring control to another web component from a JSP page uses the<br />

functionality provided by the <strong>Java</strong> Servlet API as described in “Accessing a Session” on<br />

page 125. You access this functionality from a JSP page by using the jsp:forward element:<br />

<br />

Note that if any data has already been returned to a client, the jsp:forward element will fail<br />

with an IllegalStateException.<br />

jsp:param Element<br />

When an include or forward element is invoked, the original request object is provided to the<br />

target page. If you wish to provide additional data to that page, you can append parameters to<br />

the request object by using the jsp:param element:<br />

<br />

<br />

<br />

When jsp:include or jsp:forward is executed, the included page or forwarded page will see<br />

the original request object, with the original parameters augmented with the new parameters<br />

and new values taking precedence over existing values when applicable. For example, if the<br />

request has a parameter A=foo and a parameter A=bar is specified for forward, the forwarded<br />

request will have A=bar,foo. Note that the new parameter has precedence.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!