Top Banner
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001
40

Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Object-Oriented Enterprise Application Development

Tomcat 3.2 Configuration

Last Updated: 03/30/2001

Page 2: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Topics

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

Page 3: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Application Servers

Page 4: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Functions

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.

Page 5: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Servlet 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.

Page 6: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Web 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.

Page 7: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Jakarta - 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.

Page 8: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Server Configuration

Page 9: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Tomcat Root

The directory where you installed Tomcat is called the <tomcat-root>. For instance:c:\apache\jakarta-tomcat

We'll use the <tomcat-root> as our point of reference for all Tomcat configuration and installation issues.

Page 10: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Document Root

Change to the webapps directory under the <tomcat-root>.

Create a new directory for this class called se452.

This new directory is the <document-root> for the new application.

Page 11: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Directory Structure

Within your <document-root>, create the following directory structure:/WEB-INF

/WEB-INF/classes

/WEB-INF/lib

All directory and file names are case-sensitive.

Page 12: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Server Configuration(1 of 2)

Once you've chosen a <document-root> 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 <tomcat root>/logs directory.

Page 13: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Server Configuration(2 of 2)

All tomcat configuration information is stored in <tomcat-root>/conf.

Edit the server.xml file.

Add a new Context entry to the file:<Context path="/se452" docBase="webapps/se452" debug="9" reloadable="true" trusted="false"</Context>

Page 14: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Servlet Installation

Page 15: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Purpose

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.

Page 16: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Deploying 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.

Page 17: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Deploying 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.

Page 18: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Modifying 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.

Page 19: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Modifying web.xml(1 of 2)

We create a new servlet entry in the web.xml file for each servlet:

<servlet><servlet-name> howdy</servlet-name><servlet-class> HelloWorld</servlet-class>

</servlet>

Page 20: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Modifying web.xml(2 of 2)

We next provide a translation from URLs to the servlet name slide:

<servlet-mapping><servlet-name> howdy</servlet-name><url-pattern> /greetings</url-pattern>

</servlet-mapping>

Page 21: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

JSP Installation

Page 22: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Purpose

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.

Page 23: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Custom 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.

Page 24: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Custom Tags(2 of 2)

The tag library descriptor can go in the same directory as the HTML and JSP files. This is typically the <document-root>.

The tag class package is installed within the <document-root>/WEB-INF/classes directory.

Page 25: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Changing 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.

Page 26: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Changing JavaServer Pages(2 of 3)

There is a directory called work within your <tomcat-root>. This directory contains all of the translated and compiled JSPs.

Within this directory there is a directory for each <document-root> defined to the Tomcat server.

Page 27: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Changing 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.

Page 28: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Tomcat Administration

Page 29: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Bouncing 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 <tomcat root>/bin directory.

Page 30: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Executing Servlets

Page 31: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Executing 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.

Page 32: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Executing a Servlet(2 of 2)

To execute the HelloWorld servlet we just entered into the web.xml file, use the following URI:http://localhost:8080/se452/greetings

http://localhost:8080/se452/servlet/howdy

http://localhost:8080/se452/servlet/HelloWorld

This works because of the translations established in the web.xml file.

Page 33: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Initialization Parameters

Page 34: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Purpose

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.

Page 35: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Modifying web.xml

Initialization parameters are associated with their servlet within the web.xml file:

<servlet><servlet-name>howdy</servlet-name><servlet-class>…</servlet-class>…<init-param> <param-name>parm1</param-name> <param-value>value1</param-value></init-param>

</servlet>

Page 36: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Changing 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.

Page 37: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Executing JSPs

Page 38: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Executing 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.

Page 39: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Executing a JSP(2 of 2)

To execute the HelloWorld JSP, use the following URI:http://localhost:8080/se452/HelloWorld.jsp

Unlike servlets, there are no intermediate translations from logical names to physical JSP files.

Page 40: Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.

Resources

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.