Tuesday, June 22, 2010

Java Servlet Programming












Java servlets offer a fast, powerful, portable replacement for CGI scripts. Java Servlet Programming covers everything you need to know to write effective servlets. Topics include: serving dynamic Web content, maintaining state information, session tracking, database connectivity using JDBC, and applet-servlet communication.

A few years ago, the hype surrounding applets put Java on the map as a programming language for the Web. Today, Java servlets stand poised to take Java to the next level as a Web development language. The main reason is that servlets offer a fast, powerful, portable replacement for CGI scripts. The Java Servlet API, introduced as the first standard extension to Java, provides a generic mechanism to extend the functionality of any kind of server. Servlets are most commonly used, however, to extend Web servers, performing tasks traditionally handled by CGI programs. Web servers that can support servlets include: Apache, Netscape’s FastTrack and Enterprise Servers, Microsoft’s IIS, O’Reilly’s WebSite, and JavaSoft’s Java Web Server. The beauty of servlets is that they execute within the Web server’s process space and they persist between invocations. This gives servlets tremendous performance benefits over CGI programs. Yet because they’re written in Java, servlets are far less likely to crash a Web server than a C-based NSAPI or ISAPI extension. Servlets have full access to the various Java APIs and to third-party component classes, making them ideal for use in communicating with applets, databases, and RMI servers. Plus, servlets are portable between operating systems and between servers — with servlets you can “write once, serve everywhere.”

Table of Contents 0:
Preface ............................................................................................................................. ix
1. Introduction .....................................................................................................1
History of Web Applications ...............................................................................1
Support for Servlets .............................................................................................7
The Power of Servlets ........................................................................................10
2. HTTP Servlet Basics ...................................................................................14
HTTP Basics .......................................................................................................14
The Servlet API ..................................................................................................17
Page Generation ................................................................................................19
Server-Side Includes ..........................................................................................27
Servlet Chaining and Filters .............................................................................30
JavaServer Pages .................................................................................................37
Moving On .........................................................................................................46
3. The Servlet Life Cycle ................................................................................48
The Servlet Alternative ......................................................................................48
Servlet Reloading ...............................................................................................55
Init and Destroy .................................................................................................56
Single-Thread Model .........................................................................................62
Background Processing .....................................................................................64
Last Modified Times ..........................................................................................67

4. Retrieving Information ..............................................................................70
Initialization Parameters ...................................................................................72
The Server ..........................................................................................................74
The Client ..........................................................................................................79
The Request .......................................................................................................84
5. Sending HTML Information .................................................................. 124
The Structure of a Response .......................................................................... 124
Sending a Normal Response .......................................................................... 125
Using Persistent Connections ........................................................................ 127
HTML Generation .......................................................................................... 129
Status Codes ..................................................................................................... 142
HTTP Headers ................................................................................................. 145
When Things Go Wrong ................................................................................. 151
6. Sending Multimedia Content ................................................................ 159
Images ............................................................................................................... 159
Compressed Content ....................................................................................... 188
Server Push ....................................................................................................... 191
7. Session Tracking ........................................................................................ 195
User Authorization .......................................................................................... 196
Hidden Form Fields ........................................................................................ 197
URL Rewriting ................................................................................................. 200
Persistent Cookies ............................................................................................ 202
The Session Tracking API ............................................................................... 206
8. Security .......................................................................................................... 221
HTTP Authentication ..................................................................................... 222
Digital Certificates ........................................................................................... 232
Secure Sockets Layer (SSL) ............................................................................ 234
Running Servlets Securely .............................................................................. 237
9. Database Connectivity ............................................................................. 242
Relational Databases ....................................................................................... 243
The JDBC API .................................................................................................. 246
Reusing Database Objects ............................................................................... 259
Transactions ..................................................................................................... 261
Advanced JDBC Techniques .......................................................................... 272
10. Applet-Servlet Communication ............................................................ 277
Communication Options ................................................................................ 277
Daytime Server ................................................................................................. 284
Chat Server ....................................................................................................... 317
11. Interservlet Communication .................................................................. 337
Servlet Manipulation ....................................................................................... 337
Servlet Reuse .................................................................................................... 342
Servlet Collaboration ...................................................................................... 349
Recap ................................................................................................................ 363
12. Internationalization ................................................................................. 365
Western European Languages ....................................................................... 366
Conforming to Local Customs ....................................................................... 369
Non-Western European Languages ............................................................... 371
Multiple Languages ......................................................................................... 376
Dynamic Language Negotiation .................................................................... 379
HTML Forms ................................................................................................... 389
Receiving Multilingual Input ......................................................................... 395
13. Odds and Ends ............................................................................................ 397
Parsing Parameters .......................................................................................... 397
Sending Email .................................................................................................. 401
Using Regular Expressions ............................................................................. 404
Executing Programs ........................................................................................ 407
Using Native Methods ..................................................................................... 412
Acting as an RMI Client .................................................................................. 413
Debugging ........................................................................................................ 415
Performance Tuning ....................................................................................... 423
A. Servlet API Quick Reference .................................................................. 425
B. HTTP Servlet API Quick Reference .................................................... 447
C. HTTP Status Codes ................................................................................... 472
D. Character Entities ..................................................................................... 478
E. Charsets ......................................................................................................... 484
Index ............................................................................................................................. 487

Download this book click here

Another Java books click here

No comments:

Post a Comment

Related Posts with Thumbnails

Put Your Ads Here!