Download
FAQ History |
![]() ![]() ![]() |
API
Search Feedback |
Using JSTL
JSTL includes a wide variety of tags that fit into discrete functional areas. To reflect this, as well as to give each area its own namespace, JSTL is exposed as multiple tag libraries. The URIs for the libraries are:
Table 17-1 summarizes these functional areas along with the prefixes used in this tutorial.
Thus, the tutorial references the JSTL core tags in JSP pages with the following
taglib
:In addition to declaring the tag libraries, tutorial examples access the JSTL API and implementation. In the Java WSDP, the JSTL TLDs
and
libraries are distributed in the archives standard.jar and jstl.jar in<
JWSDP_HOME
>/jstl/lib/
. If you copy these archives to the directory<
JWSDP_HOME
>/common/lib
, they will automatically be loaded into the classpath of all Web applications running on Tomcat.Tag Collaboration
Tags usually collaborate with their environment in implicit and explicit ways. Implicit collaboration is done via a well defined interface that allows nested tags to work seamlessly with the ancestor tag exposing that interface. The JSTL conditional tags employ this mode of collaboration.
Explicit collaboration happens when a tag exposes information to its environment. JSTL tags expose information as JSP EL variables; the convention JSTL follows is to use the name
var
for any tag attribute that exports information about the tag. For example, theforEach
tag exposes the current item of the shopping cart it is iterating over in the following way:In situations where a tag exposes more than one piece of information, the name
var
is used for the primary piece of information being exported, and an appropriate name is selected for any other secondary piece of information exposed. For example, iteration status information is exported by theforEach
tag via the attributestatus
.For situations where you want to use an EL variable exposed by a JSTL tag in an expression in the page's scripting language (see Chapter 19), you use the standard JSP element
jsp:useBean
to declare a scripting variable.For example,
bookshowcart.jsp
removes a book from a shopping cart using a scriptlet. The ID of the book to be removed is passed as a request parameter. The value of the request parameter is first exposed as an EL variable (to be used later by the JSTLsql:query
tag) and then declared as scripting variable and passed to thecart.remove
method:
Download
FAQ History |
![]() ![]() ![]() |
API
Search Feedback |
All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.