|
JSTL in Action Shawn Bayern 2002 | 480 pages ISBN: 1930110529 |
|||
![]() |
$39.95 | Softbound print book | |
![]() |
$20.00 | PDF ebook | |
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:
- First, create a subdirectory called WEB-INF.
- Inside this WEB-INF directory, create a filed called
web.xml with the following contents: (simply cut and
paste it from here)
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> </web-app> - Also inside this WEB-INF directory, create yet another subdirectory called lib.
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:
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/.
DESCRIPTION
| Visit the Author's book site: www.jstlbook.com |
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:
- Mixing HTML tags and JSTL
- JSTL's expression language
- Working with loops and conditions
- Painless XML processing
- Accessing databases
- Text formatting
- Internationalization
- JSTL configuration and performance
- Many examples including
- How to register and authenticate users
- Running an online survey
- How to build a discussion forum
- Designing a web portal
ABOUT THE AUTHOR...
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.

