Bnada

Solo disponible en BuenasTareas
  • Páginas : 159 (39504 palabras )
  • Descarga(s) : 0
  • Publicado : 13 de octubre de 2010
Leer documento completo
Vista previa del texto
Overview of On-Line Version
We hope you enjoy this PDF version of the international bestseller Core Servlets and JavaServer Pages (Sun Microsystems Press). If you are interested in purchasing the book, it is available through most major on-line and brick-and-mortar bookstores. See http://www.coreservlets.com for details. Interested in the sequel? Check out More Servlets and JavaServer Pages athttp://www.moreservlets.com. Looking for servlet and JSP short courses taught by the author? Visit http://courses.coreservlets.com. Available on-site at your company or at public venues.

Complete searchable PDF version offered exclusively through the Java Lobby: http://www.javalobby.org. Join now!

© Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.

ChapterTable of Contents
Acknowledgments xix About the Author xx Introduction xxi
Real Code for Real Programmers How This Book Is Organized Conventions

xxii xxiii

xxvii xxvii

About the Web Site

Part 1
Servlets 2.1 and 2.2 2

C h a p te r 1
Overview of Servlets and JavaServer Pages
1.1 Servlets

4

5

1.2 The Advantages of Servlets Over “Traditional” CGI 7 Efficient 7 Convenient 7Home page for this book: http://www.coreservlets.com. Home page for sequel: http://www.moreservlets.com. Servlet and JSP training courses: http://courses.coreservlets.com.
v

© Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.

vi

Contents

Powerful 8 Portable 8 Secure 8 Inexpensive 1.3 JavaServer Pages

9 9 10

1.4 The Advantages of JSP 10 Versus ActiveServer Pages (ASP) Versus PHP 10 Versus Pure Servlets 11 Versus Server-Side Includes (SSI) Versus JavaScript 11 Versus Static HTML 12

11

1.5 Installation and Setup 12 Obtain Servlet and JSP Software 12 Bookmark or Install the Servlet and JSP API Documentation Identify the Classes to the Java Compiler 14 Package the Classes 15 Configure the Server 16 Start the Server 17 Compile and Install YourServlets 18

14

C h ap t e r 2
First Servlets 20 21 23 24
2.1 Basic Servlet Structure

2.2 A Simple Servlet Generating Plain Text Compiling and Installing the Servlet Invoking the Servlet 25 2.3 A Servlet That Generates HTML 2.4 Packaging Servlets 27 Creating Servlets in Packages Compiling Servlets in Packages Invoking Servlets in Packages 2.5 Simple HTML-Building Utilities 2.6 The ServletLife Cycle 34 The init Method 34 The service Method 36

26 28 29 30

31

© Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.

Contents

vii

The doGet, doPost, and doXxx Methods The SingleThreadModel Interface 38 The destroy Method 38 2.7 An Example Using Initialization Parameters 2.9 Debugging Servlets

37

39 44

2.8 An Example Using ServletInitialization and Page Modification Dates

50 52

2.10 WebClient: Talking to Web Servers Interactively WebClient 52 HttpClient 55 NetworkClient 57 SocketUtil 59 CloseableFrame 60 LabeledTextField 61 Interruptible 63

C h ap t e r 3
Handling the Client Request: Form Data
3.1 The Role of Form Data

64

65 66 67 70 87

3.2 Reading Form Data from Servlets 3.4 Example: Reading All Parameters 3.5A Resumé Posting Service

3.3 Example: Reading Three Explicit Parameters

74

3.6 Filtering Strings for HTML-Specific Characters Code for Filtering 88 Example 89

C h ap t e r 4
Handling the Client Request: HTTP Request Headers
4.1 Reading Request Headers from Servlets 4.2 Printing All Headers

92

94

96 98 104 107

4.3 HTTP 1.1 Request Headers

4.4 Sending Compressed WebPages 4.5 Restricting Access to Web Pages

© Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.

viii

Contents

C h ap t e r 5
Accessing the Standard CGI Variables
5.1 Servlet Equivalent of CGI Variables

114 116 119

5.2 A Servlet That Shows the CGI Variables

C h ap t e r 6
Generating the Server Response: HTTP Status Codes
6.1 Specifying Status Codes...
tracking img