Title: Object-Oriented Enterprise Application Development
1Object-Oriented Enterprise Application Development
- Tomcat 3.2 Configuration
- Last Updated 03/30/2001
2Topics
- This Tomcat overview examines
- Creating a new server
- Starting and stopping the server
- The web.xml file
- Installing web components
- Running servlets and JavaServer Pages
3Application Servers
4Functions
- A web server is software that provides the
ability to reference both static and dynamic web
resources. - It is really designed to be a repository for all
web-based business logic. - This software abstracts the routine mechanics of
executing this components so that we don't have
to do it.
5Servlet Engines
- To execute a servlet or JavaServer Page, you must
have an appropriate engine. - The engine is the software that handles requests
for a particular type of resource. - A servlet engine handles servlet requests.
- A JSP engine handles requests for JavaServer
Pages.
6Web Connectors
- When a web server receives a request for static
content such as an HTML document, it handles the
request itself. - When a request for dynamic content, such as a
servlet, is received, the web server must hand
that request off to the web container for
processing. - This is the job of the web connector.
7Jakarta - Tomcat
- Jakarta-Tomcat is the servlet and JavaServer
Pages engine available from the Apache Group. - http//jakarta.apache.org/tomcat
- Tomcat is small, installs quickly, and is free.
The current version is Tomcat 3.2. - For this class, Tomcat will be acting as both a
web and application server.
8Server Configuration
9Tomcat Root
- The directory where you installed Tomcat is
called the lttomcat-rootgt. For instance - c\apache\jakarta-tomcat
- We'll use the lttomcat-rootgt as our point of
reference for all Tomcat configuration and
installation issues.
10Document Root
- Change to the webapps directory under the
lttomcat-rootgt. - Create a new directory for this class called
se452. - This new directory is the ltdocument-rootgt for the
new application.
11Directory Structure
- Within your ltdocument-rootgt, create the following
directory structure - /WEB-INF
- /WEB-INF/classes
- /WEB-INF/lib
- All directory and file names are case-sensitive.
12Server Configuration(1 of 2)
- Once you've chosen a ltdocument-rootgt for your
application, you need to make Tomcat aware of it. - If any part of your configuration is incorrect,
Tomcat will fail to start. - Tomcat records the problem in the lttomcat
rootgt/logs directory.
13Server Configuration(2 of 2)
- All tomcat configuration information is stored in
lttomcat-rootgt/conf. - Edit the server.xml file.
- Add a new Context entry to the file
- ltContext path"/se452"
- docBase"webapps/se452"
- debug"9"
- reloadable"true"
- trusted"false"
- lt/Contextgt
14Servlet Installation
15Purpose
- Before we can execute a servlet, it must be
installed under control of the application
server. This involves two (2) steps - Installing the servlet's class files
- Modifying the application's web.xml file.
16Deploying Servlets(1 of 2)
- Servlets are just Java classes.
- The servlet .class file is copied to the
WEB-INF/classes directory. - If you're using packages, make sure to install
them in the WEB-INF/classes directory.
17Deploying Servlets(2 of 2)
- We need to make Tomcat aware of the fact that a
new servlet has been deployed to the server. - This is done through the web.xml file.
- The web.xml file contains important configuration
information relevant to the application.
18Modifying the web.xml File
- Once the servlet class files have been installed
on the server we need to update the web.xml file. - This file allows us to map "pretty" names that
are seen by the application's clients to "ugly"
names used internally. - This file uses an XML format to specify the
servlet properties.
19Modifying web.xml(1 of 2)
- We create a new servlet entry in the web.xml file
for each servlet - ltservletgtltservlet-namegt howdylt/servlet-namegtlt
servlet-classgt HelloWorldlt/servlet-classgt - lt/servletgt
20Modifying web.xml(2 of 2)
- We next provide a translation from URLs to the
servlet name slide - ltservlet-mappinggtltservlet-namegt
howdylt/servlet-namegtlturl-patterngt
/greetingslt/url-patterngt - lt/servlet-mappinggt
21JSP Installation
22Purpose
- Before we can execute a JSP, it must be installed
under control of the application server. - In contrast to servlets, this really only
involves a single step - Install the JSP files anywhere you would install
a static HTML document. - Any embedded Java classes referenced by the JSP
must exist in the server's CLASSPATH.
23Custom Tags(1 of 2)
- To deploy a custom tag, you need to install the
two components - Tag library descriptor
- Tag class
- Each of these elements goes in a separate
location.
24Custom Tags(2 of 2)
- The tag library descriptor can go in the same
directory as the HTML and JSP files. This is
typically the ltdocument-rootgt. - The tag class package is installed within the
ltdocument-rootgt/WEB-INF/classes directory.
25Changing JavaServer Pages(1 of 3)
- Tomcat can generally tell if a JSP has changed
and will recompile the class. - However, this process is not guaranteed to be
accurate. - You may find yourself making changes to a JSP and
those changes not appearing in your output.
26Changing JavaServer Pages(2 of 3)
- There is a directory called work within your
lttomcat-rootgt. This directory contains all of the
translated and compiled JSPs. - Within this directory there is a directory for
each ltdocument-rootgt defined to the Tomcat server.
27Changing JavaServer Pages(3 of 3)
- Make sure that Tomcat has been stopped.
- Change to the directory that holds your compiled
JSPs. - Delete any of the .java or .class files as
needed. - Restart Tomcat.
28Tomcat Administration
29Bouncing the Server
- Whenever you make configuration changes to Tomcat
you should "bounce" the server. - "Bouncing" is a term we use to describe the
process of stopping and then immediately
restarting a server. - For tomcat this means issuing the shutdown and
startup commands located in the lttomcat rootgt/bin
directory.
30Executing Servlets
31Executing a Servlet(1 of 2)
- To execute a servlet, you need to issue a request
to Tomcat via a client. - The most obvious client to use is a web browser.
- By default Tomcat listens for requests on port
8080. This value can be changed, but for this
class 8080 should be fine.
32Executing a Servlet(2 of 2)
- To execute the HelloWorld servlet we just entered
into the web.xml file, use the following URI - http//localhost8080/se452/greetings
- http//localhost8080/se452/servlet/howdy
- http//localhost8080/se452/servlet/HelloWorld
- This works because of the translations
established in the web.xml file.
33Initialization Parameters
34Purpose
- Sometimes we want a servlet to initialize itself
when it's first loaded by the servlet engine. - For instance we might want to load some
configuration data before allowing the servlet to
handle client requests. - This approach can be useful for testing your code
without writing HTML pages or complex URLs.
35Modifying web.xml
- Initialization parameters are associated with
their servlet within the web.xml file - ltservletgtltservlet-namegthowdylt/servlet-namegtltserv
let-classgtlt/servlet-classgtltinit-paramgt
ltparam-namegtparm1lt/param-namegt
ltparam-valuegtvalue1lt/param-valuegtlt/init-paramgt - lt/servletgt
36Changing Initialization Parameters
- If you change the name and/or value of an
initialization parameter you'll need to bounce
the server. - Bouncing the server forces it to re-load the
server.xml and web.xml files.
37Executing JSPs
38Executing a JSP(1 of 2)
- To execute a JSP, you need to issue a request to
Tomcat via a client. - The most obvious client to use is a web browser.
- By default Tomcat listens for requests on port
8080. This value can be changed, but for this
class 8080 should be fine.
39Executing a JSP(2 of 2)
- To execute the HelloWorld JSP, use the following
URI - http//localhost8080/se452/HelloWorld.jsp
- Unlike servlets, there are no intermediate
translations from logical names to physical JSP
files.
40Resources
- Tomcat DocumentationYou should plan on spending
some time reading the configuration and user's
guides. Most of the problems that you'll
experience can have their solutions traced
directly back to one of these two guides.