Chapter 4. Setting Up the JSP Environment

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.1, 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.

Installing the Java Software Development Kit

Tomcat is a pure Java web server with support for the Servlet 2.2 and JSP 1.1 specifications. 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 install the Java 2 SDK as opposed to the slimmed-down Runtime Environment ( JRE) distribution. The reason is that JSP requires a Java compiler, which is 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 as part of the Tomcat package, 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 (http://www10.software.ibm.com/developerworks/opensource/jikes/ ). 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.2.2 and v1.3. I recommend that you use the latest version of the SDK available for your platform.

If you need an SDK for a platform other than Windows, Linux, or Solaris, there’s a partial list of ports made by other companies at Sun’s web site:

http://java.sun.com/cgi-bin/java-ports.cgi/

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 depending on 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 bin 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:

C:\>echo %JAVA_HOME%
C:\jdk1.1.2

If JAVA_HOME is not set, you can set it and include the bin directory in the PATH like this on a Windows system (assuming Java is installed in C:\jdk1.2.2):

C:\>set JAVA_HOME=C:\jdk1.1.2
C:\> set PATH=%JAVA_HOME%\bin;%PATH%

On a Windows 95/98 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 and 2000, you can set them permanently from the Environment tab in the System Properties tool.

If you use Linux or some other Unix 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 installed in /usr/local/jdk1.2.2):

[hans@gefion /]export JAVA_HOME=/usr/local/jdk1.2.2
[hans@gefion /] export PATH=$JAVA_HOME/bin:$PATH
[hans@gefion /] echo $PATH
/usr/local/jdk1.2.2/bin:/usr/local/bin:/bin:/usr/bin

Get Java Server Pages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.