Secure Cookies: Installing Tomcat and Java
1. Downloading Files. Download Tomcat from
http://tomcat.apache.org/. If you do not
have JDK 1.5 installed you need to download and install it from
This is the link to the J2SE Development Kit 5.0 Update 6 and NetBeans
IDE 5.0 Software Bundle.
2. Installing JDK. When installing java you should create a
directory where the JDK will be installed i.e. C:\Java. You will also
have to set the PATH so both java –version and javac –help gives a
result when entered in the command window.
To set your java PATH variable open your System Properties window
through the Control Panel and click on System. Then click on the
Advanced tab and select Environment Variables.
3. Environment Variable for Java. Create a new environment
variable called JAVA_HOME and enter the path to the JDK, which is
C:\Java\jdk1.5.0_06. Failing to set this variable properly will prevent
Tomcat from calling any servlets.
4. Installing Tomcat. Before you being the installation of Tomcat
create a folder called Tomcat under your C drive, which is where you
will put Tomcat5. Start the Tomcat installer and follow the on-screen
directions. When you are presented with the Installation Location screen
click the Browse button to change the installation location.
Navigate to the Tomcat folder you created in the previous step and click
Make New Folder and create a Tomcat5 folder where Tomcat will be
installed. Click OK to continue.
Your destination folder should now be C:\Tomcat\Tomcat5. Click Next to
continue the installation.
Change the HTTP Connector Port to 80, which is convenient to run Tomcat
on assuming you have no other sever already running on port 80. This is
the default HTTP port instead of the 8080 port Tomcat uses. This will
allow you to use URLs of the form http://localhost/folder instead of
http://localhost:8080/folder. Click Next to continue.
You will have to select the path of the JVM Tomcat will use. This should
already be filled in for you, so all you have to do is confirm that the
path is correct. If it is not click the Browse button and navigate to
where the JRE is installed and click OK. Click Install to complete the
installation of the JDK.
The next step is to tell Tomcat to check the modification dates of the
class files or requested servlets, and reload ones that have changed
since they were loaded into the server’s memory. This will degrade
performance; however, if you leave this off you will have to restate
Tomcat every time you recompile a servlet.
To turn on servlet reloading edit the context.xml file found at
Change <Context> to <Context reloadable = “true”>.
The invoker servlet lets you run servlets without first having to make
changes to your Web application’s deployment descriptor, which is the
web.xml file in WEB-INF. Instead, all you have to do is drop your
servlet into WEB-INF/classes and use the URL http://localhost/servlet/ServletName.
This is convenient during development but should be turned off before
deploying any real applications.
Uncomment the following servlet and servlet-mapping elements in the
C:\Tomcat\Tomcat5\conf\web.xml file. The servlet element starts at line
100 and lookes like:
. . . . . . . . . . . . . . .
The servlet-mapping element starts at line 351 and looks like:
Before you continue with this tutorial you should test Tomcat to ensure
that the installation was successful. Right click on the Apache Monitor
icon in your task bar and select Open Services.
Right click Apache Tomcat and click Start.
In the middle of the Apache Monitor icon there should be a green arrow,
indicating that an Apache service is running. If there is still a red
box like the previous image, then Tomcat did not start.
After starting Tomcat open a browser and go to
http://localhost and you
should get the Tomcat welcome page. If you receive an error message go
back through the installation steps.
5. Tomcat and Servlets. To configure Tomcat to work with servlets
you have to identify the servlet classes to the compiler because
servlets and JSP are not a part of Java 2 platform, standard edition.
You need to include the servlet-api.jar and jsp-api.jar in your
Open your System Properties window through the Control Panel and click
on System. Then click on the Advanced tab and select Environment
Create a new environment variable called CLASSPATH. Enter
C:\Tomcat\Tomcat5\common\lib\jsp-api.jar in the value for the new
environment variable. You should have a . as your first entry to
represent the current directory. All entries should be separated by a ;.
To test your servlet configuration open a browser and go to
and find the Examples menu on the left hand side. Check that both the
JSP Examples and Servlet Examples work.