This document describes how to get up and running quickly with the Standard Taglib, an implementation of 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 "standard-examples" application 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, and XML-manipulation tags. 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.
JSTL 1.1 requires a JSP 2.0 container. We recommend you test the Standard Taglib with Tomcat 5.x. JSTL 1.0 only required a JSP 1.2 container and is also available for download from Jakarta Taglibs.
To install Tomcat, follow the instructions at http://jakarta.apache.org/tomcat.
To use the Standard Taglib from its Jakarta Taglibs distribution, simply copy the JAR files in the distribution's 'lib' directory to your application's WEB-INF/lib directory. The following JAR files are included in the Standard Taglib distribution and need to be copied to your application's WEB-INF/lib directory:
Name | Description | Jar File Name |
---|---|---|
JSTL API classes
|
jstl.jar
|
|
Standard Taglib JSTL implementation classes
|
standard.jar
|
The standard tag library also has the following dependencies:
However, since all of these dependencies are included in J2SE 1.4.2 and higher, it is therefore recommended to use J2SE 1.4.2 or higher to avoid having to worry about these other dependencies.
If the java platform under which you run your JSP container does not provide these dependencies, they must be made available either globally to all web-applications by your container, or individually within the WEB-INF/lib directory of your web-application.
For convenience, these jar files have been included in directory lib/old-dependencies of this distribution.
Name | Description | Jar File Name | ||
---|---|---|---|---|
JDBC implementation classes. Already present in J2SE 1.4. |
jdbc2_0-stdext.jar
|
|||
Standard Taglib requires a JAXP 1.2 compliant parser
|
|
|||
Apache XML Xalan XSLT |
xalan.jar
|
The constituent tag libraries of Standard Taglib are as follows:
Funtional Area | URI | Prefix | Example |
---|---|---|---|
Core | http://java.sun.com/jsp/jstl/core |
c
|
<c:tagname ...> |
XML processing | http://java.sun.com/jsp/jstl/xml |
x
|
<x:tagname ...> |
I18N capable formatting | http://java.sun.com/jsp/jstl/fmt |
fmt
|
<fmt:tagname ...> |
Database access (SQL) | http://java.sun.com/jsp/jstl/sql |
sql
|
<sql:tagname ...> |
Functions | http://java.sun.com/jsp/jstl/functions |
fn
|
fn:functionName(...) |
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.
As we mentioned above, JSTL includes core tags to support iteration, conditionals, and expression-language support. It also supports EL functions for string manipulation. 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.