Tomcat, The Definitive Guide, 2008.pdf

(5108 KB) Pobierz
SECOND EDITION
Tomcat
The Definitive Guide
Jason Brittain with Ian F. Darwin
Beijing
Cambridge
Farnham
Köln
Paris
Sebastopol
Taipei
Tokyo
Tomcat: The Definitive Guide, Second Edition
by Jason Brittain with Ian F. Darwin
Copyright © 2008 O’Reilly Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (safari.oreilly.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or
corporate@oreilly.com.
Editor:
Simon St.Laurent
Production Editor:
Loranah Dimant
Copyeditor:
Nancy Reinhardt
Proofreader:
Loranah Dimant
Printing History:
June 2003:
October 2007:
First Edition.
Second Edition.
Indexer:
Tolman Creek Design
Cover Designer:
Karen Montgomery
Interior Designer:
David Futato
Illustrator:
Jessamyn Read
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc.
Tomcat: The Definitive Guide,
the image of a snow leopard, and related trade dress
are trademarks of O’Reilly Media, Inc.
Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun
Microsystems, Inc., in the United States and other countries. O’Reilly Media, Inc. is independent of Sun
Microsystems.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors
assume no responsibility for errors or omissions, or for damages resulting from the use of the
information contained herein.
This book uses RepKover
a durable and flexible lay-flat binding.
,
ISBN-10: 0-596-10106-6
ISBN-13: 978-0596-10106-0
[M]
Table of Contents
Preface
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ix
1. Getting Started with Tomcat
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
Installing Tomcat
Starting, Stopping, and Restarting Tomcat
Automatic Startup
Testing Your Tomcat Installation
Where Did Tomcat Come From?
1
17
29
34
35
2. Configuring Tomcat
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
A Word About Using the Apache Web Server
Relocating the Web Applications Directory
Changing the Port Number from 8080
Java VM Configuration
Changing the JSP Compiler
Managing Realms, Roles, and Users
Controlling Sessions
Accessing JNDI and JDBC Resources
Servlet Auto-Reloading
Customized User Directories
Tomcat Example Applications
Common Gateway Interface (CGI)
The Tomcat Admin Webapp
38
39
42
51
54
55
70
75
78
78
80
80
82
v
3. Deploying Servlet and JSP Web Applications in Tomcat
. . . . . . . . . . . . . . . . .
86
Layout of a Web Application
Deploying an Unpacked Webapp Directory
Deploying a WAR File
Hot Deployment
Working with WAR Files
The Manager Webapp
Automation with Apache Ant
Symbolic Links
93
95
100
106
107
108
111
124
4. Tomcat Performance Tuning
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
126
Measuring Web Server Performance
External Tuning
Internal Tuning
Capacity Planning
Additional Resources
127
153
156
164
167
5. Integration with the Apache Web Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
169
The Pros and Cons of Integration
Installing Apache httpd
Apache Integration with Tomcat
Tomcat Serving HTTP over the APR Connector
170
174
177
194
6. Tomcat Security
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
201
Securing the System
Multiple Server Security Models
Using the SecurityManager
Granting File Permissions
Setting Up a Tomcat chroot Jail
Filtering Bad User Input
Securing Tomcat with SSL
202
204
205
208
213
224
241
7. Configuration
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
259
server.xml
web.xml
tomcat-users.xml
catalina.policy
catalina.properties
context.xml
260
316
333
333
334
335
vi | Table of Contents
Zgłoś jeśli naruszono regulamin