APress - Apache Jakarta Tomcat (2002).pdf

(1828 KB) Pobierz
Microsoft Word - ApacheJakartaTomcat.doc
30348284.002.png
Apache Jakarta-Tomcat
by James Goodwill
ISBN: 1893115364
Apress © 2002 (237 pages)
Learn about Tomcat Server configuration, its features, and more, complete with examples and
source code.
Apache Jakarta Tomcat .................................................................................................. 8
Dedication ............................................................................................................................. 9
Preface ............................................................................................................................. 10
Introduction ...................................................................................................................... 11
About the Author ..................................................................................................... 11
About the Technical Reviewer ........................................................................... 11
Chapter 1: Jakarta Tomcat ................................................................... 12
The Jakarta Tomcat Server ................................................................................ 12
The Tomcat Manager Web Application .............................................................. 12
Specialized Realm Implementations ................................................................... 12
Tomcat Valves ........................................................................................................ 12
Further Information ................................................................................................ 12
The Architecture of Tomcat ................................................................................ 13
The Server ............................................................................................................... 14
The Service ............................................................................................................. 14
The Connector ........................................................................................................ 14
The Engine .............................................................................................................. 15
The Host .................................................................................................................. 15
The Context ............................................................................................................. 15
Java Web Applications ......................................................................................... 15
The Directory Structure ......................................................................................... 15
The Deployment Descriptor .................................................................................. 16
Packaging ................................................................................................................ 17
Requirements for Installing and Configuring Tomcat ................................ 17
Installing and Configuring Tomcat ................................................................... 18
Manually Installing to Windows NT/2000 ........................................................... 18
Installing to Linux .................................................................................................... 20
Testing Your Tomcat Installation ...................................................................... 21
Summary ................................................................................................................... 24
Chapter 2: Deploying Web Applications to Tomcat ...... 25
The Tomcat Directory Structure ........................................................................ 25
Manually Deploying Web Applications to Tomcat ...................................... 25
Creating the Web Application Directory Structure ............................................ 26
Creating a Web Application ServletContext ....................................................... 26
Adding JSPs ............................................................................................................ 27
Adding Servlets ...................................................................................................... 30
Adding Tag Libraries .............................................................................................. 33
2
30348284.003.png
Creating and Deploying a WAR File ................................................................... 37
Summary ................................................................................................................... 37
Chapter 3: Servlets, JSPs, and the ServletContext ..... 38
What Are Java Servlets? ..................................................................................... 38
The GenericServlet and HttpServlet Classes .................................................... 39
The Lifecycle of a Servlet ...................................................................................... 40
A Simple Servlet ..................................................................................................... 41
What Are JavaServer Pages? ........................................................................... 44
The Components of a JavaServer Page ............................................................ 45
The ServletContext and its Relationship to a Web Application ............. 61
The Relationship Between a Web Application and the ServletContext ......... 61
Examples of How the Web Application Affects Web Application Components
................................................................................................................................... 62
Summary ................................................................................................................... 67
Chapter 4: Using Tomcat's Manager Application ........... 69
What is the Manager Web Application? ......................................................... 69
Gaining Access to the Manager Web Application ...................................... 69
Using the Manager Web Application ............................................................... 71
install ........................................................................................................................ 71
list .............................................................................................................................. 73
reload ....................................................................................................................... 73
sessions ................................................................................................................... 74
stop ........................................................................................................................... 75
start ........................................................................................................................... 76
remove ..................................................................................................................... 76
Summary ................................................................................................................... 77
Chapter 5: Configuring Security Realms ................................. 78
Security Realms ...................................................................................................... 78
Memory Realms ...................................................................................................... 78
Protecting a Resource with a MemoryRealm .................................................... 79
JDBC Realms .......................................................................................................... 81
Creating the Users Database ............................................................................... 81
Configuring Tomcat to Use a JDBC Realm ....................................................... 87
The Benefits of Using a JDBCRealm .................................................................. 89
Accessing an Authenticated User .................................................................... 89
Summary ................................................................................................................... 91
Chapter 6: Embedding Tomcat ......................................................... 92
Embedding Tomcat into a Java Application ................................................. 92
Summary ................................................................................................................. 100
Chapter 7: Persistent Sessions ...................................................... 101
HTTP Sessions ..................................................................................................... 101
The Servlet Implementation of HTTP Sessions .............................................. 101
3
30348284.004.png
Configuring Tomcat's Persistent Session Stores ..................................... 106
The FileStore ........................................................................................................ 106
The JDBCStore ..................................................................................................... 108
Creating the Sessions Database ....................................................................... 108
Configuring Tomcat to Use a JDBCStore ........................................................ 109
Summary ................................................................................................................. 111
Chapter 8: Valves and Servlet Filters ....................................... 112
What is a Tomcat Valve? .................................................................................. 112
The Access Log Valve ......................................................................................... 112
The Remote Address Filter ................................................................................. 114
The Remote Host Filter ....................................................................................... 115
The Request Dumper Valve ............................................................................... 116
What is a Servlet Filter? ..................................................................................... 116
Deploying a Servlet Filter .................................................................................... 119
Chaining Servlet Filters ....................................................................................... 123
Summary ................................................................................................................. 127
Chapter 9: Integrating the Apache HTTP Server .......... 128
What is the Apache Web Server? .................................................................. 128
Integrating Tomcat and the Apache Web Server ..................................... 128
Summary ................................................................................................................. 132
Chapter 10: Integrating the Jakarta-Struts Project ...... 134
The Jakarta-Struts Project ................................................................................ 134
Understanding the MVC Design Pattern .......................................................... 134
The Struts Implementation of the MVC ............................................................ 134
Creating and Installing a Struts Web Application ..................................... 135
The Views .............................................................................................................. 137
The Model .............................................................................................................. 140
The Controller ....................................................................................................... 142
Walking Through the apress-struts Web Application .............................. 145
Summary ................................................................................................................. 148
Chapter 11: Integrating the Jakarta-Log4J Project ..... 149
The Jakarta-Log4J Project ................................................................................ 149
Layouts ................................................................................................................... 149
Appenders ............................................................................................................. 149
Categories ............................................................................................................. 150
Using Log4J in an Application ......................................................................... 153
Integrating Log4J into the apress Web Application ................................. 155
Summary ................................................................................................................. 159
Chapter 12: Integrating the Apache SOAP Project .... 160
Introducing the Apache SOAP Project ......................................................... 160
Integrating Apache SOAP into Tomcat ........................................................ 160
Deploying Apache-SOAP Using Tomcat .......................................................... 161
4
30348284.005.png
Creating a Sample SOAP Application .......................................................... 162
SOAP Services ..................................................................................................... 163
SOAP Clients ........................................................................................................ 167
Summary ................................................................................................................. 170
Appendix A: The server.xml File ................................................... 171
Containers ............................................................................................................... 173
The <Server> Element ...................................................................................... 173
The <Service> Element ................................................................................... 174
The <Engine> Element ...................................................................................... 175
The <Host> Element .......................................................................................... 176
The <Context> Element ................................................................................... 177
Connectors .............................................................................................................. 178
The HTTP Connector .......................................................................................... 179
The Warp Connector ........................................................................................... 180
Appendix B: The web.xml File ......................................................... 182
Overview .................................................................................................................. 182
Adding a Servlet Filter ........................................................................................ 184
Adding a Servlet Definition ............................................................................... 185
Adding a Servlet Mapping ................................................................................. 186
Configuring the Session ..................................................................................... 187
Adding a Welcome File List .............................................................................. 187
Adding a Tag Library ........................................................................................... 187
Adding a Security Constraint ........................................................................... 188
Adding a Login Config ........................................................................................ 189
List of Figures ................................................................................................... 191
Chapter 1: Jakarta Tomcat ............................................................................... 191
Chapter 2: Deploying Web Applications to Tomcat ................................. 191
Chapter 3: Servlets, JSPs, and the ServletContext ................................. 191
Chapter 4: Using Tomcat's Manager Application ..................................... 191
Chapter 5: Configuring Security Realms ..................................................... 192
Chapter 7: Persistent Sessions ....................................................................... 192
Chapter 8: Valves and Servlet Filters ........................................................... 192
Chapter 9: Integrating the Apache HTTP Server ..................................... 192
Chapter 10: Integrating the Jakarta-Struts Project .................................. 193
Chapter 12: Integrating the Apache SOAP Project ................................. 193
List of Tables ..................................................................................................... 194
Chapter 1: Jakarta Tomcat ............................................................................... 194
Chapter 2: Deploying Web Applications to Tomcat ................................. 194
Chapter 3: Servlets, JSPs, and the ServletContext ................................. 194
Chapter 4: Using Tomcat's Manager Application ..................................... 194
Chapter 5: Configuring Security Realms ..................................................... 194
5
30348284.001.png
Zgłoś jeśli naruszono regulamin