The JavaTM Web Services Tutorial
Home
TOC
PREV TOP NEXT

Using JSTL

JSTL includes a wide variety of tags that naturally fit into discrete functional areas. Therefore, JSTL is exposed via multiple TLDs to clearly show the functional areas it covers and give each area its own namespace. Table 1 summarizes these functional areas along with the logical TLD names and prefixes used in this chapter and Duke's Bookstore application.

To use the JSTL core tags in a JSP page, you declare the library using a taglib directive that references the TLD:

<%@ taglib uri="/jstl-core" prefix="c" %>
 

The JSTL tag libraries comes in two versions (see Twin Libraries). The TLDs for the JSTL-EL library are named prefix.tld. The TLDs for the JSTL-RT library are named prefix-rt.tld. Since this chapter and examples use logical TLD names, we map the names to actual TLD locations with a taglib element in web.xml:

<taglib>	
   <taglib-uri>/jstl-c</taglib-uri>	
   <taglib-location>/WEB-INF/c.tld</taglib-location>	
</taglib>
 

In the Java WSDP, the JSTL TLDs are stored in <JWSDP_HOME>/tools/jstl. When you build the Duke's Bookstore application these TLDs are automatically copied into docs/tutorial/examples/web/bookstore4/build/WEB-INF.

You can also reference a TLD in a taglib directive with an absolute URI:

When you use an absolute URI, you do not have to add the taglib element to web.xml; the JSP container automatically locates the TLD inside the JSTL library implementation.

Table 1 JSTL Tags 
Area
Function
Tags
TLD
Prefix
Core
Expression Language Support
<expr>
<set>
/jstl-c
c
Flow Control
<forEach>
<forEachToken>
<if>
<choose> <when> <otherwise>
Import
<import>
<param>
<urlEncode>
XML
Core
<parse>
<expr>
<set>
/jstl-x
x
Flow Control
<forEach>
<if>
<choose> <when> <otherwise>
Transformation
<transform>
<param>
<transformer>
I18n
Locale
<locale>
/jstl-fmt
fmt
Message formatting
<bundle>
<message>
<messageFormat>
<messageArg>
Number and date formatting
<formatNumber>
<parseNumber>
<timeZone>
<formatDate>
<parseDate>
Database

<driver>
/jstl-sql
sql
SQL
<transaction>
<query>
<update>
<param>

In addition to declaring the tag library, you also need to make the JSTL API and implementation available to the Web application. In the Java WSDP, these JSTL libraries are respectively jstl.jar and standard.jar, and are stored in <JWSDP_HOME>/tools/jstl. When you build the Duke's Bookstore application these libraries are automatically copied into docs/tutorial/examples/web/bookstore4/build/WEB-INF/lib.

Home
TOC
PREV TOP NEXT