The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Servlets
Lesson: Running Servlets

Configuring and Running Tomcat

This section shows you how to

Setting Up Tomcat

The Duke's Bookstore application runs on the Tomcat JSP and server implementation. Tomcat 4.0 implements the Java Servlet specification v2.3. Tomcat 3.x support the Java Servlet specification v2.2. Click here to download one of these implementations.

You can configure various properties of Tomcat before you start it, including the server's port, which defaults to 8080, the hostname of the server, which defaults to localhost, and the document root, which defaults to the webapps subdirectory of the Tomcat installation. To see or update these configuration values, edit the server startup file TOMCAT_HOME/conf/server.xml.

The complete binary and source code for the example is packaged in the Web application archive bookstore.war contained in the zip archive tut-bookstore-tomcat.zip. To install the application in Tomcat, download the zip archive into the directory, TOMCAT_HOME/webapps and unzip it.

When the bookstore application is accessed, Tomcat 4.0 and 3.2 automatically unpack bookstore.war into the directory TOMCAT_HOME/webapps/bookstore and add the application's context to the server startup file. The application context contains the context root, document root, what level of debugging information to provide, and whether Tomcat should monitor a servlet class for changes and reload it. If you are using Tomcat 3.1 you will need to:

When an archive is unpacked, its contents are deposited into the directories listed in the following table. This directory layout is required by the Java Servlet specification and is one that you usually will use while developing an application.

Directory Contents
bookstore HTML and image files

bookstore/WEB-INF web.xml, the Web application deployment descriptor
bookstore/WEB-INF/classes servlet classes and helper classes

Starting Tomcat

To start the server, use the Unix-based shell script or the Windows-based batch file that Tomcat provides in the directory TOMCAT_HOME/bin.

The following command starts Tomcat on Unix:

% startup.sh

The following command starts Tomcat on Windows:

C:\TOMCAT_HOME\bin> startup

Once Tomcat is executing, you can use it to test your servlets.

Stopping Tomcat

To stop the server, Tomcat provides shut-down commands in the same directory as the start-up commands.

The following command stops Tomcat on Unix:

% shutdown.sh

The following command stops Tomcat on Windows:

C:\TOMCAT_HOME\bin> shutdown


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.