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.

Including theTag Library Implementation<br />

In addition to declaring the tag library, you also must make the tag library implementation<br />

available to the web application. <strong>The</strong>re are several ways to do this. Tag library implementations<br />

can be included in a WAR in an unpacked format: Tag files are packaged in the /WEB-INF/tag/<br />

directory, and tag handler classes are packaged in the /WEB-INF/classes/ directory of the<br />

WAR. Tag libraries already packaged into a JAR file are included in the /WEB-INF/lib/<br />

directory of the WAR. Finally, an application server can load a tag library into all the web<br />

applications running on the server. For example, in the Application Server, the JSTL TLDs and<br />

libraries are distributed in the archive appserv-jstl.jar in as-install/lib/. This library is<br />

automatically loaded into the classpath of all web applications running on the Application<br />

Server, so you don’t need to add it to your web application.<br />

<strong>The</strong> iterator tag library is implemented with tag handlers. <strong>The</strong>refore, its implementation<br />

classes are packaged in the /WEB-INF/classes/ directory.<br />

Reusing Content in JSP Pages<br />

<strong>The</strong>re are many mechanisms for reusing JSP content in a JSP page. Three mechanisms that can<br />

be categorized as direct reuse are discussed here:<br />

■ <strong>The</strong> include directive<br />

■ Preludes and codas<br />

■ <strong>The</strong> jsp:include element<br />

An indirect method of content reuse occurs when a tag file is used to define a custom tag that is<br />

used by many web applications. Tag files are discussed in the section “Encapsulating Reusable<br />

Content Using Tag Files” on page 231 in Chapter 8, “Custom Tags in JSP Pages.”<br />

<strong>The</strong> include directive is processed when the JSP page is translated into a servlet class. <strong>The</strong> effect<br />

of the directive is to insert the text contained in another file (either static content or another JSP<br />

page) into the including JSP page. You would probably use the include directive to include<br />

banner content, copyright information, or any chunk of content that you might want to reuse in<br />

another page. <strong>The</strong> syntax for the include directive is as follows:<br />

<br />

For example, all the Duke’s Bookstore application pages could include the file banner.jspf,<br />

which contains the banner content, by using the following directive:<br />

<br />

Reusing Content in JSP Pages<br />

Another way to do a static include is to use the prelude and coda mechanisms described in<br />

“Defining Implicit Includes” on page 179. This is the approach used by the Duke’s Bookstore<br />

application.<br />

Chapter 5 • <strong>Java</strong>Server PagesTechnology 173

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

Saved successfully!

Ooh no, something went wrong!