JSP and JSTL Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 3.09, 2006

JSP Standard Tag Libraries (JSTL)

Part:   1  2 

JSP/JSTL Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Using Cookies

Using JavaBean Classes

HTTP Response Header Lines

Non ASCII Characters

JSTL and Expression Language

File Upload

Execution Context

JSP Elements

JSP Standard Tag Libraries (JSTL)

JSP Custom Tag

... Table of Contents

What is JSTL?

JSTL (JSP Standard Tag Libraries) is a collection of JSP custom tags developed by Java Community Process, www.jcp.org. The reference implementation is developed by the Jakarta project, jakarta.apache.org.

The latest version of JSTL is JSTL 1.1, which requires a JSP container that supports the Java Servlet 2.4 and JavaServer Pages 2.0 specifications. Jakarta Tomcat 5 supports these specifications.

The previous version is JSTL 1.0, which requires a JSP container that supports the Java Servlet 2.3 and JavaServer Pages 1.2 specifications. Jakarta Tomcat 4 supports these specifications.

Since I have Tomcat 4.1.18 installed on my machine, I will talk about JSTL 1.0 only in this section.

The goal of JSTL, as described in the specification, is to help simplify JavaServer Pages page authors' lives. To achieve this goal, JSTL has provided custom tags for many common JSP page authoring tasks that require scripting statements to manipulate server side dynamic data.

JSTL offers tags through 4 libraries:

  • core - Basic scripting functions
  • xml - XML processing
  • fmt - Internationalization of formatting
  • sql - Data base accessing

Installing JSTL 1.0 Implementation - Standard Taglib 1.0.4

Standard Taglib 1.0.4 is Jakara Taglibs's open-source implementation of the JSP Standard Tag Library (JSTL) 1.0. I did the following to download the last release of Standard Taglib 1.0.4:

  • Go to http://apache.towardex.com/jakarta/taglibs/standard-1.0/ and download jakarta-taglibs-standard-current.zip.
  • Unzip it to \local directory, and read \local\jakarta-taglibs-standard-1.0.4\README.
  • Then create a new directory in Tomcat server: "mkdir \local\jakarta-tomcat-4.1.18\webapps\ROOT\WEB-INF\lib" and copy jar files to there: "copy \local\jakarta-taglibs-standard-1.0.4\lib\*.jar \local\jakarta-tomcat-4.1.18\webapps\ROOT\WEB-INF\lib".
  • Restart Tomcat, and you are ready to try Taglib 1.0.4.

"Hello world!" with JSTL

To understand how JSTL works, let's try a very simple example, using JSTL to display "Hello world!". Here is my JSP source code, hello_jstl.jsp:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html><body>
<c:out value="Hello world!"/>
</body></html>

Save it to \local\jakarta-tomcat-4.1.18\webapps\ROOT, and run IE with url: http://localhost:8080/hello_jstl.jsp. Guess what? You will receive crashing page with an error message like: "javax.servlet.ServletException: Cannot inherit from final class".

So what happened? I really don't know. My guess is that some of the jar files from Taglib 1.0.4 are not compatible with Tomcat 4.1.18. To approve this, I removed all Taglib jar files, except standard.jar and jstl.jar, from \local\jakarta-tomcat-4.1.18\webapps\ROOT\WEB-INF\lib. I restarted Tomcat and ran IE again with url: http://localhost:8080/hello_jstl.jsp. I got the prefect message "Hello world!" in the IE window!

(Continued on next part...)

Part:   1  2 

Dr. Herong Yang, updated in 2006
JSP and JSTL Tutorials - Herong's Tutorial Notes - JSP Standard Tag Libraries (JSTL)