This book contains plenty of examples to illustrate all the JSP features. All examples were developed and tested with the JSP reference implementation, known as the Apache Tomcat server, which is developed by the Apache Jakarta project. In this chapter you will learn how to install the Tomcat server and add a web application containing all the examples used in this book. You can, of course, use any web server that supports JSP 1.2, but Tomcat is a good server for development and test purposes. You can learn more about the Jakarta project and Tomcat, as well as how you can participate in the development, at the Jakarta web site: http://jakarta.apache.org/.
Tomcat 4 is a pure Java web server with support for the Servlet 2.3 and JSP 1.2 specifications. In order to use it you must first install a Java runtime environment. If you don’t already have one, you can download a Java SDK for Windows, Linux, and Solaris at http://java.sun.com/j2se/.
I recommend that you download and install the Java 2 SDK, as opposed
to the slimmed-down Runtime Environment (JRE) distribution. The
reason is that JSP requires a Java compiler, included in the SDK but
not in the JRE. Sun Microsystems has made the
javac compiler from the SDK available separately
for redistribution by the Apache Software Foundation. So technically,
you could use the JRE and download the Java compiler separately, but
even as I write this chapter, the exact legal conditions for
distributing the compiler are changing.
Another alternative is to use the Jikes
compiler from IBM
Tomcat can be configured to use Jikes instead of the
javac compiler from Sun; read the Tomcat
documentation if you would like to try this. To make things simple,
though, I suggest installing the Java 2 SDK from Sun. The examples
were developed and tested with Java 2 SDK, Standard Edition,
v1.3.1_01 and v1.4. I suggest that you use the latest version of the
SDK available for your platform.
Also check your operating-system vendor’s web site. Most operating-system vendors have their own SDK implementation available for free.
Installation of the SDK varies per platform, but is typically easy to do. Just follow the instructions on the web site where you download the SDK.
Before you install and run Tomcat, make sure that the JAVA_HOME
environment variable is set to the installation directory of your
Java environment, and that the Java
directory is included in the PATH environment
variable. On a Windows system, you can
see if an environment variable is set by typing the following command
in a command prompt window:
If JAVA_HOME isn’t set, you can set it and include
bin directory in the PATH on a Windows
system like this (assuming Java is installed in
On a Windows 95/98/ME system, you can add
these commands to the
C:\AUTOEXEC.BAT file to set them permanently.
Just use a text editor, such as Notepad, and add lines with the
set commands. The next time you boot the PC, the
environment variables will be set automatically. For Windows NT, you
can set them permanently from the Environment tab in the System Properties tool, and for Windows 2000
and Windows XP, you can do the same with the Systems tool by first selecting the Advanced tab and then Environment Variables.
If you use Linux, Mac OS X, or
some other Unix-based platform, the exact commands depend on which
shell you use. With bash, which is commonly the
default for Linux, use the following commands (assuming Java is
export JAVA_HOME=/usr/local/jdk1.3.1_01[hans@gefion /]
export PATH=$JAVA_HOME/bin:$PATH[hans@gefion /]