By Jason Brittain, Ian F. Darwin
Cover | Table of Contents | Colophon
http://www.jetty.org), the
Locomotive Application Server (see the web archives at http://web.archive.org/web/*/http://www.locomotive.org),
Enhydra (http://www.enhydra.org),
and many others. At the same time, commercial servlet containers
became available as the industry embraced the Java servlet standard;
some of these were WebLogic's Tengah,
ATG's Dynamo, and LiveSoftware's
JRun.|
Script
|
Purpose
|
|---|---|
|
catalina
|
The main Tomcat script, which runs the
java
command to invoke the Tomcat startup and shutdown classes. |
|
cpappend
|
Used internally, and then only on Windows systems, to append items to
Tomcat classpath environment variables.
|
|
digest
|
Makes a
crypto digest of Tomcat passwords. Use it
to generate encrypted passwords. |
|
jasper
|
tomcat4 service when it enters the multiuser run
level.root user you can simply chkconfig
tomcat4 for the run levels of your choice.# tksysv &
# ntsysv
tomcat4 service.tomcat4
service, you probably didn't install Tomcat as a
Linux RPM. This procedure works for RPM-based installations only.tomcat4 listing (an asterisk will appear between
the brackets to signify that it is selected).
<security-constraint>
in a web application's
WEB-INF/web.xml file defines how user and role
information will be stored and how users will be authenticated for
the web application. There are many ways of configuring each; feel
free to mix and match.UserDatabaseRealm, JDBCRealm,
JNDIRealm, and JAASRealm. Java
developers can also create additional realm implementations to
interface with their own user and password stores. To specify which
realm should be used, insert a HttpSession object that temporarily stores
information about a user, including a unique session identifier and
references to Java objects that the web application stores as
attributes of the session. Typical uses of sessions include shopping
carts and sites that require users to sign in. Usually, sessions are
set to time out after a configurable period of user inactivity. Once
a session has timed out, it is said to be an
invalid session; if the user makes a new HTTP
request to the site, a new, valid session must be created, usually
through a relogin.Managers that control the logic of
how sessions are handled, and it has session
Stores to save and load sessions. Not every
Manager uses a Store to persist
sessions; it is an implementation option to use the
Store interface to provide pluggable session store
capabilities. Robust session Managers will
implement some kind of persistent storage for their sessions,
regardless of whether they use the Store
interface. Specifying a Manager implementation
works in a similar fashion to specifying a Realm:<Manager className="some.manager.implementation.className"
customAttribute1="some custom value"
customAttribute2="some other custom value"
<!-- etc. -->
/>Manager and Store objects, but
some options are set in web.xml (that is, at the
context level). These options are described in detail in Chapter 7, under the Section 7.2.6 and Section 7.2.9 element headings.DataSource. If you're not sure,
look in the web.xml file for the application and
search for something like this:<resource-ref>
<description>
The database DataSource for the Acme web application.
</description>
<res-ref-name>
jdbc/JabaDotDB
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>Context ctx = new InitialContext( );
DataSource ds = (DataSource)
ctx.lookup("java:comp/env/jdbc/JabaDotDB");
Connection conn = ds.getConnection( );
... Java code that accesses the database ...
conn.close( );DataSource is an object that can hand out JDBC
Connection objects on demand, usually from a pool
of preallocated connections.jdbc/JabaDotDB tells you what you need to
configure a reference for in the server.xml
file. Find the Context element for your web
application, and insert Resource and
ResourceParam elements similar to those shown in
Example 2-12.reloadable attribute in the web
application's Context element (in
web.xml) and restart Tomcat. Once
you've done this, you can still reload the servlet
classes in a given Context by using the
Manager application (detailed earlier in this
chapter).CATALINA_BASE environment variable to point to a
new directory on disk where the Tomcat instance can find its set of
configuration and other writeable directories.http://www.cs.myuniversity.edu/~ian http://members.mybigisp.com/~ian
Listener elements. The
Listener's
className attribute should be
org.apache.catalina.startup.UserConfig, with the
userClass attribute specifying one of several
mapping classes. If your system runs Unix, has a standard
/etc/passwd file that is readable by the account
running Tomcat, and that file specifies users' home
directories, use the PasswdUserDatabase mapping
class:<Listener className="org.apache.catalina.startup.UserConfig" directoryName="public_html" userClass="org.apache.catalina.startup.PasswdUserDatabase" />
HomesUserDatabase class:<Listener className="org.apache.catalina.startup.UserConfig" directoryName="public_html" homeBase="/home" userClass="org.apache.catalina.startup.HomesUserDatabase" />
Context element from the file
server.xml in the Tomcat
conf directory. Look for the section beginning
like this:<!-- Tomcat Examples Context -->
<Context path="/examples" docBase="examples" debug="0"
reloadable="true" crossContext="true">
<!-- Context content -->
</Context><!-- and --> around the
element, because comments in XML do not nest! If you
don't want to deal with this issue and
haven't made any other changes to your
server.xml file, you can use the provided
server-noexamples.xml. This file is almost
identical to the default server.xml, except that
it does not contain the examples
Context.Context.#include mechanism, but it is
slightly enhanced for use in web pages. For example, in one of our
web sites we have a table navigator that is meant to appear at the
left of each page. Instead of copying the table cells into each page,
we store them in their own small file. Then, each page that needs the
navigator accesses it using code like this:<!--#include virtual=/"tablenav.html" -->
jsp:include element,
there might be cases when a large number of legacy pages must be
served, and you prefer to keep them as SHTML files, perhaps for
compatibility with other servers. It's probably not
worthwhile to convert SHTML files to JSP just so you can process them
as JSPs. In fact, Tomcat provides an SSI servlet for this very
purpose. To enable it, you need only do the following:CLASSPATH. (This file is normally not installed
with the extension jar, which reduces overhead
by keeping it out of the CLASSPATH if
you're not using it.)ssi from Tomcat's
web.xml file to your
application's web.xml (this is
around line 180 in the distribution). Alternatively, if you want all
contexts to have SSI processing, simply uncomment this
servlet's definition in Tomcat's
global #! /usr/local/bin/python # Trivial CGI demo print "content-type: text/html" print "" print "<html><head>Welcome</head>" print "<body><h1>Welcome to the output of a CGI under Tomcat</h1>" print "<p>The subject says all.</p>" print "</body></html>"
docBase attribute of the
Context element is absolute, i.e., the absolute
path of CATALINA_HOME/server/webapps/manager.
Alternatively, you could just remove the auto-deployment file and
specify the Admin context manually in your
server.xml file. On machines that will not be
managed by this application, you should probably disable it
altogether by simply removing
CATALINA_BASE/webapps/admin.xml.
/ /index.jsp /products.jsp /widgets/index.html /widgets/pricing.jsp /images/logo.png /WEB-INF/web.xml /WEB-INF/classes/com/acme/PriceServlet.class /WEB-INF/classes/DataHelper.class /WEB-INF/lib/acme-util.jar
Context) and is covered in detail in Chapter 7.servlet-mapping element in the
WEB-INF/web.xml file, for example. Listing the
servlet in the descriptor is required if you want to provide an
alternate mapping, pass any initialization parameters to the servlet,
specify loading order on startup, and so on. The
servlet element is an XML tag that appears near
the start of web.xml, and it is used for all of
these tasks.<servlet>
<icon>
<small-icon>/images/tomcat_tdg16x16.jpg</small-icon>
</icon>
<servlet-name>InitParams</servlet-name>
<display-name>InitParams Demo Servlet</display-name>
<description>
A servlet that shows use of both servlet- and
webapp-specific init-params
</description>
<servlet-class>InitParams</servlet-class>
<init-param>
<param-name>myParam</param-name>
<param-value>
A param for the Servlet:
Forescore and seven years ago...
</param-value>
</init-param>
<load-on-startup>25</load-on-startup>
</servlet>Context
element for your web application, and place it in
$CATALINA_BASE/webapps. The web application
itself can then be stored anywhere on your filesystem.DefaultContext element
in Tomcat's server.xml file
(see Chapter 7 for information on setting up a
DefaultContext element).Context
element and any subelements that are appropriate for your web
application. These files are like Context elements
cut out of the server.xml file, hence the name
context fragment.<!--
Context configuration file for the Tomcat Administration
Web App
$Id: admin.xml,v 1.2 2001/10/27 18:56:23 craigmcc Exp $
-->
<Context path="/admin" docBase="../server/webapps/admin"
debug="0" privileged="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_admin_log." suffix=".txt"
timestamp="true"/>
</Context><!--
Context fragment for deploying MyWebApp.war
-->
<Context path="/demo" docBase="webapps/MyWebApp.war"
debug="0" privileged="true">
<Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"
/>
</Context>Context entry for the
Manager application in Tomcat's
server.xml, and you must provide a username and
password for access to the application.Context for the
application in Tomcat's
server.xml file: <!-- Manager (Tomcat) -->
<Context path="/manager" docBase="manager"
debug="0" privileged="true"/>Context fragment distributed with Tomcat, so you
don't even need to add the context. This step is
necessary only on Tomcat 4.0.x versions.UserDatabaseRealm,
you'll need to add the user to the
tomcat-users.xml file, which is discussed more
fully in Chapter 2. For now, just edit this file,
and add a line like this after the existing user entries (changing
the password to something a bit more secure):<user name="iadmin"
password="deep_dark_secret"
roles="manager"
/>OK - Listed applications for virtual host localhost /webserver:running:0 /javacook:running:0 /darian:running:0 /seating:running:0 /openbsd:running:0 /jabadot:running:0 /manager:running:0
http://www.softwareqatest.com/qatweb1.html#LOAD
for a list. A few measuring tools of note are the Apache Benchmark
(ab, included with distributions of the standard
Apache web server), Jeff Poskanzer's
http_load from Acme Software (see http://www.acme.com/software/http_load), and
JMeter from Apache Jakarta (see http://jakarta.apache.org/jmeter). The first
two tools and JMeter are at opposite ends of the spectrum in terms of
complexity and functionality.