CARVIEW |

Deploying Web Applications to Tomcat
04/19/2001In this article we are going to cover the deployment of web applications using Tomcat. We are performing a manual deployment to fully explain the steps involved when deploying a web application.
The best way to describe the deployment process is to create a web application of our own that includes the important components found in most Java web applications; then package it for deployment. The following sections will take you through the steps involved in deploying a web application. The name of our web application will be onjava
.
In this article, we
- create the web application directory structure,
- create a web application ServletContext,
- add JSPs,
- add Servlets,
- add Tag Libraries, and
- create and deploy a WAR file.
Creating the Web Application Directory Structure
The first thing you need to do is create the directory structure that will contain the application. We discussed this structure in Part 1, Java Web Applications, and I include the relevant details in Table 1.
Table 1. The Web Application Directory Structure |
|
Directory |
Contains |
/onjava | This is the root directory of the web application. All JSP and XHTML files are stored here. |
/onjava/WEB-INF |
This directory contains all resources related to the application that are not in the document root of the application. This is where your web application deployment descriptor is located. Note that the WEB-INF directory is not part of the public document. No files contained in this directory can be served directly to a client. |
/onjava/WEB-INF/classes | This directory is where servlet and utility classes are located. |
/onjava/WEB-INF/lib | This directory contains Java Archive files that the web application depends upon. For example, this is where you would place a JAR file that contained a JDBC driver. |
The name of our web application, onjava
, is the root
of our directory structure.
While in development I suggest creating the directory directly in
the Tomcat /webapps
directory. When it comes time for
deployment, you can package your web application into a WAR file and
go though the production deployment process.
The last step in creating the web application directory structure
is adding a deployment descriptor. At this point you'll be creating a
default web.xml file that contains only the DTD, describing the
web.xml
file, and an empty <webapp/> element. Listing 1
contains the source for a default web.xml
file.
Listing 1 web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"https://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
</web-app>
Now copy this file to the TOMCAT_HOME/onjava/WEB-INF/
directory, and we'll begin adding web application components to it in
the following sections.

Popular Topics
ActionScript | Ajax |
Apache | C# |
CSS | Flex |
Head First | iPhone |
Java | JavaScript |
Linux | Missing Manuals |
MySQL | Open Source |
Perl | PHP |
Photoshop | Python |
Ruby | Web 2.0 |
XML |
Browse Books & Videos
- Business & Culture
- Databases
- Design & Graphics
- Digital Audio & Video
- Digital Photography
- Hardware
- Home & Office
- Networking & Sys Admin
- Operating Systems
- Programming
- Science & Math
- Security
- Software Engineering
- The Web
News Topics
analysis2009 cloudcomputing economics economy freesoftware google government iphone javascript linux microsoft mobile ooxml opensource oscon perl politics privacy python rails ruby security socialnetworking standards twitter web20 xml xquery xrx xslt
International Sites
![]() ©2009, O'Reilly Media, Inc. (707) 827-7000 / (800) 998-9938 All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. |
About O'Reilly
Academic Solutions Authors Contacts Customer Service Jobs Newsletters O'Reilly Labs Press Room Privacy Policy RSS Feeds Terms of Service User Groups Writing for O'Reilly Content Archive Business Technology Computer Technology Microsoft Mobile Network Operating System Digital Photography Programming Software Web Web Design |
More O'Reilly Sites
O'Reilly Radar Ignite Tools of Change for Publishing Digital Media Inside iPhone O'Reilly FYI makezine.com craftzine.com hackszine.com perl.com xml.com Partner Sites InsideRIA java.net O'Reilly Insights on Forbes.com |
More Technology News Ars Technica BBC News - Technology CNET News - Technology Guardian - Technology News Mashable ReadWriteWeb Slashdot TechCrunch Technology Review The New York Times - Technology The Washington Post - Technology Wired News |