[ Team LiB ] Previous Section Next Section

Installing and Using JSTL

The Apache Jakarta project includes a good implementation of JSTL (http://jakarta.apache.org/taglibs/index.html). Sun's JSTL page (http://java.sun.com/products/jsp/jstl) contains a link to the Apache implementation, as well as documentation for JSTL. The Jakarta implementation of JSTL keeps pace with the JSTL standard, so by the time a new version of the JSTL standard comes out, Jakarta already has a working version. The Jakarta JSTL implementation contains a number of JAR files. To include JSTL in your Web application, simply include these files in your WEB-INF/lib directory.

Depending on your version of Java, you may need to install additional JAR files. For example, if you use a JDK older than version 1.3, you may need an XML parser. You can place any additional JAR files in the WEB-INF/lib directory as well.

JSTL consists of four separate tag libraries: Core, XML, SQL, and Fmt (formatting) and a functions library. To use any of these libraries, you must include a taglib directive at the top of each JSP that uses the library.

To use the Core library, use the following directive:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

The prefix attribute specifies the prefix used in the tag name for a particular library. For example, the Core library includes a tag named out. When combined with a prefix of c, the full tag would be <c:out>. You are free to use any prefix you like, but you must use different prefixes for each of the four standard tag libraries.

To use the XML library, use the directive

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

To use the SQL library, use the directive

<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>

To use the Fmt library, use the directive

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

To use the Functions library, use the directive

<%@ taglib prefix="fn" uri="http://java.sun.com/jstl/functions" %>

You must also put the corresponding .tld file for each tag library in your WEB-INF directory and use the <taglib> in your web.xml file element to include the tag library:

    [ Team LiB ] Previous Section Next Section