ebook img

Professional Apache Tomcat 6 PDF

642 Pages·2007·6.13 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Professional Apache Tomcat 6

Professional Apache Tomcat 6 Vivek Chopra Sing Li Jeff Genender Wiley Publishing, Inc. ffffiirrss..iinndddd iiiiii 77//1111//0077 66::5544::4433 PPMM Professional Apache Tomcat 6 Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-471-75361-2 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data Chopra, Vivek. Professional Apache Tomcat 6 / Vivek Chopra, Sing Li, and Jeff Genender. p. cm. Includes index. ISBN 978-0-471-75361-2 (paper/website) 1. Apache Tomcat. 2. Web servers. 3. Web site development. 4. Internet programming. I. Li, Sing. II. Genender, Jeff M. III. Title. TK5105.8885.A63C47 2007 005.7'1376—dc22 2007020134 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for per- mission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indian- apolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent profes- sional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. ffffiirrss..iinndddd iivv 77//1111//0077 66::5544::4444 PPMM To Rebecca and Rohan, thanks for all your patience and support. —Vivek To my guiding light and spiritual support for the last two decades, Kim. —Sing To my wonderful wife, Nazarena, and my children, Madisyn, Weston, and Coleton. I could not have done this without you. —Jeff ffffiirrss..iinndddd vv 77//1111//0077 66::5544::4455 PPMM About the Authors Vivek Chopra has more than 13 years of experience as a software architect, developer, and team lead and has worked in a number of Silicon Valley companies and startups. He writes actively on technology and is the author of more than half a dozen books on Java, open source software, XML, and Web services. Vivek has pending patents on Web service technologies, and has been a Java Community Process (JCP) member for the past three years. He also serves on the expert group for JSR 280 (XML API for Java ME). Sing Li (who was bitten by the microcomputer bug in the late 1970s) has grown up with the Micropro- cessor Age. His first personal computer was a $99 do-it-yourself Netronics COSMIC ELF with 256 bytes of memory, mail-ordered from the back pages of Popular Electronics magazine. A 20-year industry vet- eran, Sing is a system developer, open source software contributor, and freelance writer specializing in Java technology, and embedded and distributed systems architecture. He regularly writes for several popular technical journals and e-zines, and is the creator of the “Internet Global Phone,” one of the very first Internet phones available. He has authored and co-authored a number of books across diverse tech- nical disciplines including Geronimo, Tomcat, JSP, servlets, XML, Jini, media streaming, device drivers, and JXTA. Jeff Genender has over 18 years of software architecture, team lead, and development experience in multiple industries. Jeff is an active committer and Project Management Committee (PMC) member for Apache Geronimo, and a committer on OpenTerracotta, OpenEJB, ServiceMix, and Mojo (Maven plug- ins). Jeff also serves as a member of the Java Community Process (JCP) expert group for JSR-313 (Java Platform, Enterprise Edition 6 [Java EE 6] Specification) as a representative of the Apache Software Foundation. Jeff is an open source evangelist and has successfully brought open source development efforts, initiatives, and success stories into a number of Global 2000 companies, saving these organiza- tions millions in licensing costs. ffffiirrss..iinndddd vviiii 77//1111//0077 66::5544::4455 PPMM Credits Executive Editor Vice President and Executive Group Publisher Bob Elliott Richard Swadley Development Editor Vice President and Executive Publisher Sydney Jones Joseph B. Wikert Technical Editors Project Coordinator, Cover Rupert Jones Adrienne Martinez Anne Horton Proofreader Copy Editor Kathryn Duggan Nancy Rapoport Indexer Editorial Manager Johnna VanHoose Dinse Mary Beth Wakefield Anniversary Logo Design Production Manager Richard Pacifico Tim Tate ffffiirrss..iinndddd iixx 77//1111//0077 66::5544::4455 PPMM Contents Introduction xxiii Chapter 1: Apache Tomcat 1 Humble Beginnings: The Apache Project 2 The Apache Software Foundation 3 Tomcat 3 Distributing Tomcat: The Apache License 4 Comparison with Other Licenses 5 The Big Picture: Java EE 6 Java APIs 6 The Java EE APIs 7 Java EE Application Servers 8 “Agree on Standards, Compete on Implementation” 8 Tomcat and Application Servers 9 Tomcat and Web Servers 9 Summary 10 Chapter 2: Web Applications: Servlets, JSPs, and More 13 A Brief History of Web Applications 13 CGI Scripts: The First Mechanism for Dynamic Content 13 Server Side Java: Servlets 14 JavaServer Pages 19 JSP Tag Libraries 22 JSP EL 23 MVC Architecture 24 Using Appropriate Web Technologies 25 Building and Distributing Web Applications 26 Summary 27 Chapter 3: Tomcat Installation 29 Installing the Java Virtual Machine 29 Installing the JVM on Windows 30 Installing the JVM on Linux 32 ffttoocc..iinndddd xxii 77//1111//0077 11::4488::4477 PPMM Contents Installing Tomcat 34 Deciding Which Distribution to Install 34 Verifying the Downloaded File 35 Tomcat Windows Installer 36 Installing Tomcat on Windows Using the ZIP File 41 Installing Tomcat on Linux 42 Building Tomcat from Source 44 Do You Need to Build Tomcat from the Source Code? 44 Downloading the Source Release 44 Subversion Repository 45 Building a Source Release 45 The Tomcat Installation Directory 46 Installing APR 47 Troubleshooting and Tips 48 Class Version Error 49 The Port Number Is in Use 49 Running Multiple Instances 49 A Proxy Is Blocking Access 49 Summary 50 Chapter 4: Tomcat Architecture 51 Tomcat Directory Overview 51 bin Directory 52 conf Directory 52 lib Directory 53 logs Directory 53 temp Directory 53 webapps Directory 53 work Directory 54 An Overview of Tomcat Architecture 54 The Server 55 The Service 56 The Remaining Classes in the Tomcat Architecture 59 Connector Architecture 59 Communication Paths 60 Connector Protocols 61 Choosing a Connector 63 Lifecycle 64 Lifecycle Interface 65 LifecycleListener Interface 65 Configuration by Architecture 66 Summary 67 xii ffttoocc..iinndddd xxiiii 77//1111//0077 11::4488::4488 PPMM Contents Chapter 5: Basic Tomcat Configuration 69 Tomcat 6 Configuration Essentials 70 Files in $CATALINA_HOME/conf 71 Basic Server Configuration 71 Server Configuration via the Default server.xml 72 Operating Tomcat in Application Server Configuration 75 Web Application Context Definitions 82 The Default context.xml File 82 Authentication and the tomcat-users.xml File 86 The Default Deployment Descriptor — web.xml 86 How server.xml, Context Descriptors, and web.xml Work Together 91 Fine-Grained Access Control: catalina.policy 94 catalina.properties: Finer-Grained Control over Access Checks 97 Bootstrapping Configuration 97 A Final Word on Differentiating Between Configuration and Management 98 Tomcat 6 Web-Based GUI Configurator 98 Summary 100 Chapter 6: Advanced Tomcat Features 103 Valves — Interception Tomcat-Style 104 Standard Valves 104 Access Log Implementation 105 Scope of Log Files 106 Single Sign-On Implementation 108 Multiple Sign-On Without the Single Sign-On Valve 109 Configuring a Single Sign-On Valve 111 Form Authenticator Valve 112 Restricting Access via a Request Filter 112 Remote Address Filter 112 Remote Host Filter 113 Configuring Request Filter Valves 113 Request Dumper Valve 114 Persistent Sessions 115 The Need for Persistent Sessions 115 Configuring a Persistent Session Manager 115 JNDI Resource Configuration 118 What Is JNDI? 118 Tomcat and JNDI 119 Typical Tomcat JNDI Resources 120 Configuring Resources via JNDI 121 xiii ffttoocc..iinndddd xxiiiiii 77//1111//0077 11::4488::4488 PPMM Contents Configuring a JDBC DataSource 124 Configuring Mail Sessions 126 Configuring Lifecycle Listeners 129 Lifecycle Events Sent by Tomcat Components 129 The <Listener> Element 129 Tomcat 6 Lifecycle Listeners Configuration 130 Summary 133 Chapter 7: Web Application Configuration 135 Understanding the Contents of a Web Application 135 Public Resources 136 The WEB-INF Directory 138 The META-INF Directory 139 Understanding the Deployment Descriptor (web.xml) 140 The Servlet 2.3–Style Deployment Descriptor 141 The Servlet 2.4/2.5–Style Deployment Descriptor 154 Summary 171 Chapter 8: Web Application Administration 173 Sample Web Application 173 Tomcat Manager Application 175 Enabling Access to the Manager Application 176 Manager Application Configuration 178 Tomcat Manager: Web Interface 180 Displaying Tomcat Server Status 180 Managing Web Applications 181 Deploying a Web Application 182 Tomcat Manager: Managing Applications with Ant 182 Known Issue: Failure While Undeploying Web Applications on Windows 188 Tomcat Manager — Using HTTP Requests 189 List Deployed Applications 190 Deploying a New Application 190 Installing/Deploying Applications in Tomcat 6 191 Deploying a New Application Remotely 192 Deploying a New Application from a Local Path 192 Reloading an Existing Application 194 Listing Available JNDI Resources 195 Listing OS and JVM Properties 196 Stopping an Existing Application 196 Starting a Stopped Application 197 Undeploying a Web Application 198 xiv ffttoocc..iinndddd xxiivv 77//1111//0077 11::4488::4499 PPMM Contents Displaying Session Statistics 198 Querying Tomcat Internals Using the JMX Proxy Servlet 199 Setting Tomcat Internals Using the JMX Proxy Servlet 200 Possible Errors 200 Security Considerations 201 Tomcat Deployer 203 Summary 203 Chapter 9: Class Loaders 205 Class Loader Overview 205 Standard Java SE Class Loaders 207 More on Class Loader Behavior 210 Creating a Custom Class Loader 211 Why Is a Custom Class Loader Needed for Tomcat? 211 Security and Class Loaders 212 Class Loader Delegation 212 Core Class Restriction 212 Separate Class Loader Namespaces 213 SecurityManager 213 Tomcat and Class Loaders 214 System Class Loader 215 Endorsed Standards Override Mechanism 215 Common Class Loader 215 Web Application Class Loader 216 Dynamic Class Reloading 217 Common Class Loader Pitfalls 218 Packages Split Among Different Class Loaders 218 Singletons 218 XML Parsers 219 Summary 220 Chapter 10: HTTP Connectors 221 HTTP Connectors 222 Tomcat 6 HTTP/1.1 Connector 223 The Advanced NIO Connector 227 Comet Asynchronous IO Support 228 The Native APR Connector 228 Configuring Tomcat for CGI Support 232 Configuring Tomcat for SSI Support 234 Configuring the Tomcat 6 SSI Servlet 235 Configuring the Tomcat 6 SSI Filter 237 xv ffttoocc..iinndddd xxvv 77//1111//0077 11::4488::4499 PPMM

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.