JSTL in Action

Shawn Bayern

2002 | 480 pages | B&W
ISBN: 9781930110526

$39.95 Softbound print + PDF eBook
$31.99 eBook edition (PDF only)



JSTL is an important simplification of the Java web platform. With JSTL, page authors can now write dynamic pages using standard HTML-like tags and an easy-to-learn expression language. JSTL is a standard from the Java Community Process, and its expression language will become part of JSP 2.0.

JSTL in Action shows you how to write rich, dynamic web pages without programming. From simple loops to tricky XML processing, every feature of JSTL is covered and exercised in numerous useful examples. Whether you are a novice page author or an experienced Java programmer, this book shows you easy ways to create powerful web sites.

To help readers who don't already have a JSP container run the examples in the book, there's a free companion download here. This bundle contains a ready-to-run JSP container, a JSTL implementation, and all the book's examples.

What's Inside:


Shawn Bayern is a research programmer at Yale University and coauthor of Manning's Web Development with Java Server Pages. He is the reference implementation lead for JSTL.

Sample Chapters

Chapters 5 and 11, as well as the "About the Book" section and Appendix B of JSTL in Action are available here in Portable Document Format (PDF); you need Adobe's free Acrobat Reader software to view them. You may download Acrobat Reader here.

Download 'About the Book'

Download Chapter 5

Download Chapter 11

Download Appendix A


Instructions for installing the hsqldb database can be found here as a single PDF file. (See Chapter 9 of JSTL in Action for further information.)

You'll need Adobe's Acrobat Reader software to view the file.


"Websphere developers (both web application and portlet development) will get the most out of this book when it comes to the IBM/Lotus world. The use of JSTL will reduce the code complexity of your JSP pages and speed up your development efforts....If you are developing JSP pages and haven't looked into the use of the JSTL area, get this book. It will save you time and effort in your coding, and you'll be glad you did."
--Portland Domino/Notes User Group

"...the book squarely focuses on the JSTL and does a remarkably good job of unveiling relevant details... The author's style is fluid, concise, entertaining, and informative...The examples are illustrative and comprehensive enough to show how much easier it is to implement high-level solutions with JSTL rather than build more complicated infrastructure at a lower level... This book will do the trick."
--Java Pro Magazine, April 2003

" the only book that shows you how to build JSP Web sites without assuming you know Java first...the best choice for those less technical members of the team."

"a thorough, yet easy, introduction to the subject aimed at the authors of dynamic Web pages, be they Java programmers with experience or novice level developers...don't overlook this title if you are involved in JSP development...The technical tips alone are worth the book's price...

"A well-written text is typical for books on Java from this publisher...In a strange way the text transcends the boundaries of a technical book...The genre does not leave much opportunity for authors to wear their heart on their sleeve. Things appear to be different with Mr. Bayern. He intentionally puts his own 'issues' on the dust jacket, starting with an eccentric dedication to a fictitious spouse and choosing to illustrate his technical point with a host of examples and real life comparisons varying from romantic to (melo)dramatic or even pathetic (he calls them 'my off-beat humor'). I'll leave it to you to decide whether the smart guy takes his audience for a ride or tries to reveal a deeper human emotion beneath his passion to JSTL tags."
--Member of Java Metroplex Users Group of Dallas/Ft.Worth, Texas
--Java Retroflex Users Group

"...an excellent introduction to the new JavaServer Pages Standard Tag Library...Mr. Bayern clearly has the teacher's gift, and I'll look forward to more books form him in the future."

"...the book squarely focuses on the JSTL and does a remarkably good job of unveiling relevant details...The author's style is fluid, concise, entertaining, and informative...The examples are illustrative and comprehensive enough to show how much easier it is to implement high-level solutions with JSTL rather than build more complicated infrastructure at a lower level...While this book may be geared primarily at nonprogrammers, any Java developer interested in Web technology should become familiar with JSTL. This book will do the trick."
--Java Pro Magazine, April 2003

"A nicely written book about JSTL (JSP Standard Tag Library). Its expected audience consists of HTML and JSP developers who can be unfamiliar with Java, as well as experienced Java programmers.

"A reader without programming experience will probably benefit most. The book is beginner-friendly on all levels of organization. Terminology is relaxed without being sloppy: correspondence to both formal lexicon and "field jargon" is given. Every important word and concept is explained, often with vivid (or bizarre, depending on your taste) metaphors. It will be long time before I forget author's definition of "scope" that compared it to flying rats...

"The words "in action" in the book's title aren't just words, it is a methodological principle. The discussion concentrates on practice rather than theory and specifications; each JSTL tag comes with examples - from "elementary"tasks - how to set encoding or print numbers in assorted formats, to parsing XML and performing SQL queries. There are more complex projects, like writing an online survey, message board and a simple web portal from scratch - toys that look so real and their code so simple that you want to try it out.

"The last part is targeted at Java programmers and deals with issues like performance improving, configuration, and developing custom tags - JSTL supports even this!

"And if all this is not enough, then you should know: there are jokes scattered throughout the book, so you do not want to skip pages for not to miss one!"

Source Code

jstlbook.war A WAR (ZIP) file of the book's examples plus an embedded database, ready to run in any JSP 1.2 container. To use this file, simply copy it into the appropriate directory for your JSP container (the webapps directory under Tomcat, for example). (2.6 Mb)
A bundle that wraps 'jstlbook.war' inside the Tomcat container, making the package ready to run. See below for instructions on installing this bundle. (The files are the same, except that one's packaged as a ZIP and the other as a gzipped TAR file. ~5.2 Mb)

Procedures for running the bundle:

1. Download the JDK (either 1.3 or 1.4) from Sun's site:


2. Set the environment variable JAVA_HOME to point to the directory to which you installed the JDK (for instance, "D:\j2sdk1.4.0"). On Windows, for this sample directory, the command is

SET JAVA_HOME=d:\j2sdk1.4.0

On Unix, the command depends on your shell. It's typically either

export JAVA_HOME


setenv JAVA_HOME /path/to/j2sdk1.4.0

3. Run bin/startup.bat (Windows) or bin/startup.sh (Unix) at the root of the ZIP or tar.gz file.

4. That's all -- Tomcat and the book's examples are running. You can access them at the following URL:


Tomcat Setup

Installing Tomcat and JSTL

I've written the following set of instructions for readers of JSTL in Action who don't already have a JSP container like Tomcat to experiment with. JSTL requires a JSP container, so if you're starting from scratch, setting up Tomcat is a good first step.

(We've also made available a bundle containing Tomcat, JSTL, and the book's examples in a ready to run format. This bundle will be useful to you if you don't want to bother downloading and installing Tomcat yourself.)

To get up and running with JSTL and Tomcat, follow these steps:

1. Ensure you have a suitable Java environment

Before you do anything, you need to have the Java 2 Standard Edition Software Development Kit (J2SE SDK) installed. The most recent version of the J2SE SDK is 1.4, though earlier versions will work fine with Tomcat. If you already have downloaded a Java environment from Sun or another vendor, you can probably use it without trouble.

Otherwise, download the J2SE 1.4 SDK from http://java.sun.com/j2se/1.4/download.html. This package is a self-installing distribution that will unpack itself, by default, into your current directory. You'll need to note the name of the directory into which you unpack the distribution. For instance, if you're using a Unix machine and your home directory is /home/bayern, then if you unpack the Java distribution from within your home directory, it will install itself into a directory that looks like /home/bayern/j2sdk1.4.0_01.

Whether you're using an old or a new Java environment, you need to set the environment variable named JAVA_HOME to the directory where you installed Java. Commands for setting environment variables vary from platform for platform, but the most common examples follow:

setenv JAVA_HOME /home/bayern/j2sdk1.4.0_01 (Unix / csh)

JAVA_HOME /home/bayern/j2sdk1.4.0_01 (Unix / sh)
export JAVA_HOME

set JAVA_HOME=c:\j2sdk1.4.0_01 (Windows)

2. Download Tomcat

Once you've unpacked your Java environment, you should download Tomcat from the Apache Jakarta web site. The URL for Tomcat's main page is http://jakarta.apache.org/tomcat, and the download site is a link from this page labeled "Binaries." (For version Tomcat 4.0.4, which was the most recently released version of Tomcat when these instructions was written, the direct download site is http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.4/bin/.)

There are two branches for each current version of Tomcat. The first is a large package that contains a number of important support libraries that were needed on older (pre-1.4) versions of Java. The second is a "lite edition" that is smaller, for the J2SE 1.4 SDK contains a number of these support libraries -- and Tomcat can rely on their presence and avoid requiring that you download them anew. If you use J2SE 1.4, I recommend you download this lite edition; you can notice it by the abbreviation LE in the filename.

3. Unpack Tomcat

Once you have downloaded Tomcat, you need to unpack it. The distributors of Tomcat normally offer both .zip files and .tar.gz files. Pick whichever you're more comfortable with, and unpack it into a convenient directory.

4. Download and unpack JSTL

Now that you've unpacked Tomcat, you're actually a step away from running it; it doesn't need any custom configuration on most systems. However, to use Tomcat with JSTL, you'll need to download and install a JSTL implementation. I recommend you download the Jakarta Taglibs implementation, which is known as the Standard Taglib, from http://jakarta.apache.org/taglibs. The URL from which you can download directly is http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/. As with Tomcat, .zip and .tar.gz files are available; you may pick whichever is more familiar.

Unpack the JSTL implementation into a convenient directory, separate (for now) from the one you used for Tomcat.

5. Create a sample web application

Inside your Tomcat directory is a subdirectory called webapps. This directory will contain your individual web applications. See Part I of JSTL in Action for more information on what the term web application means in the context of JSP; to summarize, a web application is a collection of JSP pages and other resources that function as a unit.

Create a directory under webapps corresponding to the name of the web application you'd like to create. For the rest of the tutorial, we'll call it sample.

After you create this directory, you'll want to add a few things to it:

Thus, a sample web application has a structure and location like this:

    [ Tomcat base directory ]
        \- webapps
            \- sample
                 \- WEB-INF
                    \- web.xml
                    \- lib

6. Copy JSTL into your web application

The final directory that you created in step 5, WEB-INF/lib, is for Java libraries that you want to make accessible to your web application. The Standard Taglib contains a set of such libraries. Under the directory where you unpacked the Standard Taglib, there is a directory called lib. Copy everything in this directory to your web application's WEB-INF/lib directory.

7. Start Tomcat

You're now ready to go. To prepare to start Tomcat, change into your base Tomcat directory, and type one of the following commands:

  • bin/startup.sh (Unix-based systems)
  • bin/startup.bat (Windows)
  • Tomcat is now running. If you add JSP pages to your web application's directory (that is, the same one into which you added the WEB-INF directory above), then you can load them using your web browser. If your web application is called sample and you inserted a file called test.jsp into its root directory (that is, next to WEB-INF), then you could load it using the following URL: http://localhost:8080/sample/test.jsp

    These instructions should help you get started experimenting with JSTL. If you have any questions, you can ask them in JSTL in Action's Author Online forum, which you can get to from http://www.manning.com/bayern. If you have detailed question about Tomcat, you might want to join the tomcat-user@jakarta.apache.org mailing list; see http://jakarta.apache.org/site/mail.html for further instructions.

    Tomcat's developers also maintain detailed instructions on Tomcat at http://jakarta.apache.org/tomcat/.