JaVa
   

Using JSTL

As mentioned earlier, JSTL includes tags that fit into four areas, each of which is exposed via its own tag library descriptors (TLDs). To use a tag, its corresponding library must be referenced in the JSP. For example, to use the JSTL XML tags in a JSP page, the following taglib directive should be included before the tag is used:

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



As a result of this relative directive, when the JSP is compiled into a servlet, the container will look for the URI in the Web app's WEB-INF file and its corresponding tag library descriptor.

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


Alternatively, the JSP can follow the absolute declaration, where the library is referenced by its absolute namespace, in which case the container will resolve this to the appropriate tag library:

<%@ taglib uri="http://java.oracle.com/jstl/xml" prefix="x" %>


You must have the descriptor (e.g., the x.tld file) and JSTL implementation classes available to the Web app that uses these tags. The TLD and JAR files are packaged with the Java WSDP reference implementation of JSTL. (The JSTL TLD files are in <JWSDP_HOME>/tools/jstl/tlds and the JAR files are in <JWSDP_HOME>/tools/jstl/standard/lib/standard.jar and <JWSDP_HOME>/tools/jstl/jstl.jar). Table B.2 summarizes details of the different actions; Table B.3 gives the absolute URIs for JSTL tags.

Table B.2: JSTL tags

Tag

Functional area

Specific tags

TLD

TLD prefix

Core functionality

Expression language support

catch

out

remove

set

/jstl-c

c

Flow control

choose

forEach

forTokens

if

URL management

import

url

XML specific

Core

parse

out

set

/jstl-x

x

Flow control

choose

forEach

if

Transformation

Transform

Internationalization

Locale

setLocale

/jstl-fmt

fmt

Message formatting

bundle

message

setBundle

Number and date formatting

formatNumber

formatDate

parseDate

parseNumber

setTimeZone

timeZone

Database access

SQL

setDataSource

query

transaction

upate

dateParam

param

/jstl-sql

sql

Table B.3: Absolute URI for JSTL tags

Tag area

Absolute URI in JSP taglib directive

Core

http://java.oracle.com/jstl/core

XML

http://java.oracle.com/jstl/xml

Internationalization

http://java.oracle.com/jstl/fmt

SQL

http://java.oracle.com/jstl/sql


JaVa
   
Comments