Академический Документы
Профессиональный Документы
Культура Документы
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network.
'. \
Wiley Publishing, Inc. '
Contents
Acknowledgments About the Author Introduction xv xvii xix
Part I
Chapter 1
1 2 3 4 5 6 7 7 9 10 10 10 12 12 12 13 14 14 14 15 vii
Chapter 2
Starting Up Tomcat for the First Time Windows Linux, OS X, and other Unix
viii
Contents Starting Tomcat on Boot Windows Linux Mac OS X Server Mac OS X Other Unix Flavors First Look at Tomcat Summary
Chapter 3 Configuring Tomcat
17 17 17 19 19 23 24 24 25 28 29 30 31 31 34 34 35 36 37 38 38 40 40
41 44 46 47
Tomcat Configuration Files The HTTP 1.1 Connector The WAEP Connector Other Connectors Webapp Contexts Web Application Configuration Configuring Tomcat with Apache Changes to Apache Configuring Tomcat with Microsoft IIS Adding Registry Entries Virtual Host Configuration Apache Virtual Hosting Tomcat Virtual Hosting Summary Chapter 4 Hello World Wide Web Handling a Request What's In a Response Summary
Anatomy and Life Cycle of a Servlet
Chapter 5
49
49 52 57 57 59 60 61 62 64 65 65 67 69 70 71
73
The Servlet Life Cycle Servlet Anatomy Life Cycle Events j avax. servlet. ServletContextlistener javax.servlet.ServletContextAttributelistener javax.servlet.http.HttpSessionListener javax.servlet.http.HttpSessionAttributeListener Configuring Life Cycle Listeners Summary Chapter 6 Configuring Web Applications Installing in /webapps The Deployment Descriptor: web.xml WAR Files Configuring Servlets from the server.xml File Summary The server.xml File in Depth New Features in Tomcat 4.1 The Basic Model The <Server/> Node The <Service/> Container
Chapter 7
74 74 75 76
Contents
The <Engine/> Container The <Realm/> Node The <Logger/> Node The <Host/> Container The <Context/> Container The <Valve/> Node Access Log Valve Remote Host Filter and Remote Address Filter Request Dumper Valve Single Sign On Valve Additional Valves The <Resources/> Node The <Loader/> Node The <Manager/> Node The <Connector/> Node The Coyote HTTP/1.1 Connector Server Proxy Connectors The JK 2 Connector The Webapp Connector The <Factory/> Node The Tomcat Web Server Administration Tool Setup Security Using the Administration Tool Summary
76 77 77 78 82 84 84 85 86 86 86 87 87 89 91 92 93 94 94 95 98 98 99 99 99
Chapter 8
101
101 103 103 107 111 113 113 113 114 117
Chapter 9
119
120 121 121 122 123 123 125 126 126 128
Contents
Chapter 10
The Model-View-Controller Architecture What Is MVC Architecture? Model Objects View Objects Communication between Controller and View Controller Objects Advantages of MVC Clean Design Encapsulation Extensibility Reuse and Refactoring Using MVC on the Web Summary
129 129 130 130 130 131 131 131 131 132 132 132 134
Part II
Chapter 11
Tomcat Development
JavaServer Pages What Does a JSP Page Look Like? JSPs Are Really Servlets Jasper: The Tomcat JSP Compiler Expressions Scriptlets and Declarations Page Directives Including Pages Working with Beans Scope Debugging JSPs Summary Tag Libraries Writing a Basic Tag Library Packaging the Tag Using the Tag A Word about Namespaces A Practical Tag Example Tags with Bodies JSTL: The JSP Standard Tag Library Other Tag Libraries from the ASF Summary MVC with Struts Overview of Struts A Typical Model 1-Style JSP Application The Department Model The Department Database Schema The JSPs for the Model 1 Department Application The MVC Struts Version of the Application List Department Action Action Details The Struts Deptlisting View The Struts Custom Tags 155 135 137 144 145 145 146 148 150 152 152 154 155_ 156 157 158 159 159 167 178 180 182 185 184 185 185 193 194 200 201 203 203 204
Chapter 12
Chapter 13
Contents
Employeelisting: Action and View Managing Form Data with Struts Templates Struts and XDoclet Summary
Chapter 14
Template Systems
Why Templates Rather than JSP? What Is Velocity? Installing Velocity An Example of Using Velocity The Velocity Template Language References Directives Setting Variables Conditionals Loops Including Files Macros Summary
229
229 230 230 231 233 233 238 238 240 241 243 244 245
Chapter 15
Session Management
State Management and HTTP Using HttpSession Expiring Sessions Setting Your Own Cookies Additional Cookie Attributes Summary
247
247 249 267 267 268 269
Chapter 16
271
271 273 273 274 274 274 275 275 276 276 277 282 282 289
Chapter 17
Database-Aware Objects
The Factory and Modified Singleton Design Patterns The Design Setting Up the Project SmartObject.java ObjectFactoryjava Getting Existing Objects Storing the Data
289
290 294 295 295 299 300 308
xii
Contents
Automated Commits Creating New Objects Using the Framework Adding the getObjects() Method Some Remaining Issues Summary Chapter 18 Security Configuring Tomcat SSL, HTTPS, and TLS Using Tomcat Behind Another Server to Provide HTTPS Setting Up the HTTPS Connector Digital Certificates Configuring the Connector The Security Manager Bad Code Pernicious Code Weak, Dangerous, Badly Written, or Misconfigured Code Tomcat and the Security Manager Using the Security Manager with Tomcat Debugging Permissions Issues Permissions Running as an Unprivileged User Servlet Development Using Onetime Passwords Discovering the Protocol of Your Connection Using Certificates as User Credentials Other Techniques for Validating Identity Summary
312 316 319 327 331 331 555 334 334 335 335 336 338 339 339 340 340 341 345 345 345 346 347 347 348 350 351 351
Chapter 19
555
354 355 358 361 361 361 366 369 369 369 370 370 371 372
Chapter 20
575
374 375 375 377 378 378
Contents
xiii
Creating a Master Build File 380 Using the War Task to Create a WAR File 381 Using XDoclet's webdoclet Task to Create Deployment Descriptors 382 Running Ant for the First Time 392 Using the XDoclet's webdoclet Task to Create Custom Tag TLDs 393 Standard Targets 400 The Hello World Model Project 402 Overview of Model Classes 402 Creating a Project Directory Structure for Model 403 Creating a Build File for a Shared Library 404 Analysis of the Model Project Build File 404 Running an Ant Build File 408 The Hello World Application Project 409 Overview of Application Java Classes 409 Creating a Project Directory Structure for the Application 409 Creating a Manifest File for a Stand-alone Application 410 Creating an Ant Build File for a Stand-Alone Application 410 The Hello World Main Project 413 Creating a Master Build File 413 Analysis of the Master Build File 414 The Applet Project 415 Overview of the Applet Class 415 Creating a Build File for the Applet 419 Building the Applet with Ant 420 Hello World Recap 421 Hello World Model 2 and J2EE 421 The Web Application Project 422 Building and Deploying the Web Application 432 Running the Web Application 434 Summary 437 Appendix A Appendix B Server Configuration (server.xml) Reference The Deployment Descriptor (web.xml) Reference Index 459
451
479