Escolar Documentos
Profissional Documentos
Cultura Documentos
In the beginning..
Web servers serving static html
Web servers using cgi for dynamic content Modules to handle dynamic content
Ex: Apache and Mod-Perl
Java thrown in JSP converted to a Servlet the first time accessed Servlets stay in memory - big plus over CGI
History of Tomcat
Java Web Server
First servlet container Created by Sun to demonstrate Servlet technology
Jserv
Integrated with Apaches web server Created by ASF (Apache Software Foundation)
Tomcat 3.x
Merger of Java Web Server & Jserv Reference implementation of Servlet & JSP specs
5
Tomcat 5.x
the most recent version Builds on version 4 Updated to implement Suns latest Servlet & JSP specifications
J2EE (cont)
Examples of J2EE application servers
BEA Weblogic IBM Websphere Jboss
Tomcat Features
Runs as a service (Windows) or daemon(Unix)
Run stand-alone or on beefier web server Manager Application provides tools:
Deploy, undeploy, list, start and stop applications
10
Directory Structure
bin Start and Stop Server Scripts + useful Tools common common used classes and libraries (Tomcat and Applications) conf Config files of Tomcat
11
Directory Structure
logs
Logs all log files of Tomcat server classes and libraries only for Tomcat + system Web applications, e.g. the manager App or the Admin Tool
12
Directory Structure
shared
classes and libraries only for Web applications temp the JVM temporary files puts here webapps contains all user-defined Web applications work contains temporary files of Tomcat, e.g. to Servlets compiled JSP files
13
Directory Structure
14
Client2
Servlet2
Client3
15
Tomcat Components
Server
Service Connectors Engine Realm
Valves
Logger Host Context
16
and one or more containers Catalina - the servlet container Jasper - the JSP engine Coyote - the web connector
17
The Connector
Manages the connection between
applications and clients Point at which client requests are received Implements org.apache.catalina.Connector Example implementations:
Coyote (HTTP) - the default Apache Jserv Protocol (SSL)
18
19
The Container/Engine
Request processing component
Passes the request and response objects
from connector to the servlet Implements org.apache.catalina.Container Catalina is the default implementation
20
21
init() Container gets a request and calls service() The Servlet receives HttpServletRequest and HttpServletResponse objects Servlet finds HTTP request data in the request object - ex: form data, cookies, headers
22
output to the response object Container passes the response object back to the connector Connector sends reply back to client Container calls destroy() before removing a servlet instance
23
Why Tomcat?
Highly configurable
Modular design means you can
Configuration directives that can be included in a conf/server.xml file to configure the behavior of the Tomcat 4 servlet/JSP container The configuration element descriptions are organized into the following major categories: Top Level Elements - <Server> is the root element of the entire configuration file, while <Service> represents a group of Connectors that is associated with an Engine. Connectors - Represent the interface between external clients sending requests to (and receiving responses from) a particular Service. Containers - Represent components whose function is to process incoming requests, and create the corresponding responses. An Engine handles all requests for a Service, a Host handles all requests for a particular virtual host, and a Context handles all requests for a specific web application. Nested Components - Represent elements that can be nested inside the element for a Container. Some elements can be nested inside any Container, while others can only be nested inside a Context
25
26
Description
Java class name of the implementation to use. This class must implement the org.apache.catalina.Server interface. If no class name is specified, the standard implementation will be used The TCP/IP port number on which this server waits for a shutdown command. This connection must be initiated from the same server computer that is running this instance of Tomcat The command string that must be received via a TCP/IP connection to the specified port number, in order to shut down Tomcat
port
shutdown
27
Standard Implementation The standard implementation of Server is org.apache.catalina.core.StandardServer. It supports the following additional attributes (in addition to the common attributes listed above):
Attribute Description
The level of debugging detail logged by this Server to the associated Logger. Higher numbers generate more detailed output. If not specified, the default debugging detail level is zero (0).
debug
28
Nested Components
The following components may be nested
29
combination of one or more Connector components that share a single Engine component for processing incoming requests. One or more Service elements may be nested inside a Server element.
30
Common Attributes
Attribute
className
Description
Java class name of the implementation to use. This class must implement the org.apache.catalina.Service interface. If no class name is specified, the standard implementation will be used The display name of this Service, which will be included in log messages if you utilize standard Catalina components. The name of each Service that is associated with a particular Server must be unique
name
31
Standard ImplementationThe standard implementation of Service is org.apache.catalina.core.StandardService. It supports the following additional attributes (in addition to the common attributes listed above):
Attribute
debug
Description
The level of debugging detail logged by this Service to the associated Logger. Higher numbers generate more detailed output. If not specified, the default debugging detail level is zero (0).
32
Nested Components
The only components that may be nested
inside a Service element are one or more Connector elements, followed by exactly one Engine element
33
34
Description
Java class name of the implementation to use. This class must implement the org.apache.catalina.Context interface. If not specified, the standard value (defined below) will be used. Set to true if you want cookies to be used for session identifier communication if supported by the client (this is the default). Set to false if you want to disable the use of cookies for session identifier communication, and rely only on URL rewriting by the application The Document Base (also known as the Context Root) directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file).
35
cookies
docBase
Description
The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing. All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts
36
Description
The default host name, which identifies the Host that will process requests directed to host names on this server, but which are not configured in this configuration file. This name MUST match the name attributes of one of the Host elements nested immediately inside Logical name of this Engine, used in log and error messages
name
38
Nested Components
You can nest one or more Host elements inside this Engine element,
each representing a different virtual host associated with this server. At least one Host is required, and one of the nested Hosts MUST have a name that matches the name specified for the defaultHost attribute, listed above You can nest at most one instance of the following utility components by nesting a corresponding element inside your Engine element
Logger - Configure a logger that will receive and process all log messages for this Engine, plus messages from Connectors associated with this Engine in the surrounding Service. In addition, this Logger will log messages from subordinate Hosts and Contexts, unless overridden by a Logger configuration at a lower level. Realm - Configure a realm that will allow its database of users, and their associated roles, to be shared across all Hosts and Contexts nested inside this Engine, unless overridden by a Realm configuration at a lower level.
39
which is an association of a network name for a server (such as "www.mycompany.com" with the particular server on which Catalina is running
40
Common Attributes
All implementations of Host support the following attributes:
Attribute
appBase
Description
The Application Base directory for this virtual host. This is the pathname of a directory that may contain web applications to be deployed on this virtual host. You may specify an absolute pathname for this directory, or a pathname that is relative to the $CATALINA_HOME directory. Network name of this virtual host. One of the Hosts nested within an Engine MUST have a name that matches the defaultHost setting for that Engine.
name
41
Nested Components
You can nest one or more Context elements inside this Host
element, each representing a different web application associated with this virtual host. In addition, you can nest a single DefaultContext element that defines default values for subsequently deployed web applications. You can nest at most one instance of the following utility components by nesting a corresponding element inside your Host element Logger - Configure a logger that will receive and process all log messages for this Host, plus messages from Contexts associated with this Host . Realm - Configure a realm that will allow its database of users, and their associated roles, to be shared across all Contexts nested inside this Host
42
References
How Tomcat Works: A Guide to Developing Your Own Java Servlet Container
(Kurniawan & Deck)
Tomcat-Einfuehrung.pdf
43