The JavaTM Web Services Tutorial
Home
TOC
Index
PREV TOP NEXT
Divider

Using JSTL

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

Table 16-1 JSTL Tags 
Area
Function
Tags
TLD
Prefix
Core
Expression Language Support
catch
out
remove
set
/jstl-c
c
Flow Control
choose
  when
  otherwise
forEach
forTokens
if
URL Management
import
  paramredirect
  param
url
  param
XML
Core
out
parse
set
/jstl-x
x
Flow Control
choose  when  otherwise
forEach
if
Transformation
transform
  param
I18n
Locale
setLocale
/jstl-fmt
fmt
Message formatting
bundle
message
  param
setBundle
Number and dateformatting
formatNumber
formatDate
parseDate
parseNumber
setTimeZone
timeZone
Database

setDataSource
/jstl-sql
sql
SQL
query
  dateParam
  param
transaction
update  dateParam
  param

For example, 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 the examples discussed in this chapter use logical TLD names, we map the logical names to actual TLD locations with taglib elements in the Web application deployment descriptor. Here is the entry that maps the core library logical TLD name /jstl-c to its location /WEB-INF/c.tld:

<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/tlds. When you build the Duke's Bookstore application these TLDs are automatically copied into <JWSDP_HOME>/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.

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

Divider
Home
TOC
Index
PREV TOP NEXT
Divider

This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.

All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.