|
Home TOC |
|
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
taglibdirective 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 namedprefix-rt.tld. Since this chapter and examples use logical TLD names, we map the names to actual TLD locations with ataglibelement inweb.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 intodocs/tutorial/examples/web/bookstore4/build/WEB-INF.You can also reference a TLD in a
taglibdirective with an absolute URI:
- Core:
http://java.sun.com/jstl/ea/core- XML:
http://java.sun.com/jstl/ea/xml- Internationalization:
http://java.sun.com/jstl/ea/fmt- SQL:
http://java.sun.com/jstl/ea/sqlWhen you use an absolute URI, you do not have to add the
taglibelement toweb.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. In the Java WSDP, these JSTL libraries are respectively
jstl.jarandstandard.jar,and are stored in<JWSDP_HOME>/tools/jstl. When you build the Duke's Bookstore application these libraries are automatically copied intodocs/tutorial/examples/web/bookstore4/build/WEB-INF/lib.
|
Home TOC |
|