This document describes how to get up and running quickly with the Java Server Pages Standard Tag Library (JSTL). This document may be useful to page authors and tag developers who are interested in JSTL's functionality. Using the JSTL examples is also a great way to familiarize yourself with JSTL's functionality and use.
JSTL is the Java Server Pages Standard Tag Library. It is an effort of the Java Community Process (JCP) and comes out of the JSR-052 expert group.
JSTL encapsulates, as simple tags, core functionality common to many JSP applications. For example, instead of suggesting that you iterate over lists using a scriptlet or different iteration tags from numerous vendors, JSTL defines a standard <forEach> tag that works the same everywhere.
This standardization lets you learn a single tag and use it on multiple JSP containers. Also, when tags are standard, containers can recognize them and optimize their implementations.
JSTL provides support for core iteration and control-flow features, text inclusion, internationalizaton-capable formatting tags, XML-manipulation tags, and useful EL functions. The expression language that JSTL defined in the 1.0 version of the specification is now an integral part of the JSP 2.0 specification. Developers may also be interested in JSTL's current extensibility mechanisms; JSTL currently provides a framework for integrating custom tags with JSTL tags.
Please see the Release Notes document for information on any release changes.
Sun's official JSTL page at http://java.sun.com/products/jstl lists books and other resources that will help you learn JSTL.
Since the Web Services Pack supports a JSP 2.0 container and makes all JSTL jar files globally available to all web applications, you are all set to immediately take advantage of JSTL 1.1 in your webapps.
The constituent tag libraries of Standard Taglib are as follows:
|I18N capable formatting||http://java.sun.com/jsp/jstl/fmt||
|Database access (SQL)||http://java.sun.com/jsp/jstl/sql||
Using the Standard Taglib libraries is simple; you simply need to import them into your JSP pages using the taglib directive. For instance, to import the 'core' JSTL library into your page, you would include the following line at the top of your JSP page, as follows:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
The EL makes it easy for page authors to access and manipulate application data. For an overview of the EL, see Chapter 3 of the JSTL Specification.Complete definition of the Expression Language may be found in the JSP 2.0 specification.
As we mentioned above, JSTL includes core tags to support iteration, conditionals, and expression-language support. For more information on precisely how these tags work, you should read the JSTL specification. Here, we just offer a quick roadmap of each feature in order to help orient you.
Developers of custom tags should also read the JSTL specification. JSTL defines some abstract classes that assist with rapid development of tags and promote integration of custom tags with JSTL's tag set.
For instance, extending javax.servlet.jsp.jstl.core.ConditionalTagSupport lets you write a conditional tag by merely implementing a single method that returns a boolean value correspondent with your tag's desired conditional behavior; also, this base class promotes JSTL's recommended model of conditional-tag design.
Similarly, javax.servlet.jsp.jstl.core.IteratorTagSupport lets you easily implement iteration tags. The handlers for the <forEach> and <forTokens> tags extend this class and thus implement the javax.servlet.jsp.jstl.core.IteratorTag interface, which provides a well-defined mechanism for iteration tags to communicate with custom subtags you can write. See the "standard-examples" application for one example of how you might use such custom subtags.