Core Servlets and JavaServer Pages, Vol. 1: Core Technologies [2. ed., Nachdr] 0130092290, 0076092016816, 9780130092298

The J2EE(TM) Platform has become the technology of choice for developing professional e-commerce applications, interacti

1,221 98 8MB

English Pages XXXIII, 691 Seiten Illustrationen, Diagramme [728] Year 2003;2004

Report DMCA / Copyright

DOWNLOAD FILE

Core Servlets and JavaServer Pages, Vol. 1: Core Technologies [2. ed., Nachdr]
 0130092290, 0076092016816, 9780130092298

Table of contents :
COVER ......Page 1
CONTENTS......Page 6
ACKNOWLEDGMENTS......Page 24
About the Authors......Page 25
INTRODUCTION......Page 26
Volume 2......Page 28
Distinctive Features......Page 29
How This Book Is Organized......Page 31
Conventions......Page 32
About the Web Site......Page 33
1.1 A Servlet’s Job......Page 36
1.2 Why Build Web Pages Dynamically?......Page 38
1.3 A Quick Peek at Servlet Code......Page 39
1.4 The Advantages of Servlets Over “Traditional” CGI......Page 40
1.5 The Role of JSP......Page 44
PART I: SERVLET TECHNOLOGY......Page 48
CHAPTER 2 SERVER SETUP AND CONFIGURATION......Page 50
2.1 Download and Install the Java Software Development Kit (SDK)......Page 51
2.2 Download a Server for Your Desktop......Page 52
2.3 Configure the Server......Page 55
2.4 Configuring Apache Tomcat......Page 56
2.5 Configuring Macromedia JRun......Page 61
2.6 Configuring Caucho Resin......Page 67
2.7 Set Up Your Development Environment......Page 68
2.8 Test Your Setup......Page 72
2.9 Establish a Simplified Deployment Method......Page 82
2.10 Deployment Directories for Default Web Application: Summary......Page 85
2.11 Web Applications: A Preview......Page 88
CHAPTER 3 SERVLET BASICS......Page 98
3.1 Basic Servlet Structure......Page 99
3.2 A Servlet That Generates Plain Text......Page 101
3.3 A Servlet That Generates HTML......Page 103
3.4 Servlet Packaging......Page 105
3.5 Simple HTML-Building Utilities......Page 107
3.6 The Servlet Life Cycle......Page 110
3.7 The SingleThreadModel Interface......Page 119
3.8 Servlet Debugging......Page 123
4.1 The Role of Form Data......Page 128
4.2 Reading Form Data from Servlets......Page 130
4.3 Example: Reading Three Parameters......Page 133
4.4 Example: Reading All Parameters......Page 137
4.5 Using Default Values When Parameters Are Missing or Malformed......Page 141
4.6 Filtering Strings for HTML-Specific Characters......Page 153
4.7 Automatically Populating Java Objects from Request Parameters: Form Beans......Page 160
4.8 Redisplaying the Input Form When Parameters Are Missing or Malformed......Page 167
CHAPTER 5 HANDLING THE CLIENT REQUEST: HTTP REQUEST HEADERS......Page 180
5.1 Reading Request Headers......Page 181
5.2 Making a Table of All Request Headers......Page 183
5.3 Understanding HTTP 1.1 Request Headers......Page 185
5.4 Sending Compressed Web Pages......Page 189
5.5 Differentiating Among Different Browser Types......Page 194
5.6 Changing the Page According to How the User Got There......Page 196
5.7 Accessing the Standard CGI Variables......Page 200
CHAPTER 6 GENERATING THE SERVER RESPONSE: HTTP STATUS CODES......Page 208
6.1 Specifying Status Codes......Page 209
6.2 HTTP 1.1 Status Codes......Page 211
6.3 A Servlet That Redirects Users to Browser-Specific Pages......Page 217
6.4 A Front End to Various Search Engines......Page 219
CHAPTER 7 GENERATING THE SERVER RESPONSE: HTTP RESPONSE HEADERS......Page 228
7.1 Setting Response Headers from Servlets......Page 229
7.2 Understanding HTTP 1.1 Response Headers......Page 230
7.3 Building Excel Spreadsheets......Page 237
7.4 Persistent Servlet State and Auto-Reloading Pages......Page 239
7.5 Using Servlets to Generate JPEG Images......Page 250
8.1 Benefits of Cookies......Page 262
8.2 Some Problems with Cookies......Page 264
8.3 Deleting Cookies......Page 267
8.4 Sending and Receiving Cookies......Page 269
8.5 Using Cookies to Detect First-Time Visitors......Page 272
8.6 Using Cookie Attributes......Page 274
8.7 Differentiating Session Cookies from Persistent Cookies......Page 277
8.8 Basic Cookie Utilities......Page 281
8.9 Putting the Cookie Utilities into Practice......Page 283
8.10 Modifying Cookie Values: Tracking User Access Counts......Page 285
8.11 Using Cookies to Remember User Preferences......Page 288
9.1 The Need for Session Tracking......Page 296
9.2 Session Tracking Basics......Page 298
9.3 The Session-Tracking API......Page 302
9.4 Browser Sessions vs. Server Sessions......Page 304
9.5 Encoding URLs Sent to the Client......Page 305
9.6 A Servlet That Shows Per-Client Access Counts......Page 306
9.7 Accumulating a List of User Data......Page 310
9.8 An On-Line Store with a Shopping Cart and Session Tracking......Page 314
PART II:JSP TECHNOLOGY......Page 334
CHAPTER 10 OVERVIEW OF JSP TECHNOLOGY......Page 336
10.1 The Need for JSP......Page 337
10.2 Benefits of JSP......Page 338
10.3 Advantages of JSP Over Competing Technologies......Page 339
10.4 Misconceptions About JSP......Page 342
10.5 Installation of JSP Pages......Page 345
10.6 Basic Syntax......Page 347
11.1 Creating Template Text......Page 352
11.2 Invoking Java Code from JSP......Page 353
11.3 Limiting the Amount of Java Code in JSP Pages......Page 354
11.4 Using JSP Expressions......Page 358
11.5 Example: JSP Expressions......Page 361
11.6 Comparing Servlets to JSP Pages......Page 363
11.7 Writing Scriptlets......Page 365
11.8 Scriptlet Example......Page 367
11.9 Using Scriptlets to Make Parts of the JSP Page Conditional......Page 369
11.10 Using Declarations......Page 371
11.11 Declaration Example......Page 373
11.12 Using Predefined Variables......Page 375
11.13 Comparing JSP Expressions, Scriptlets, and Declarations......Page 377
CHAPTER 12 CONTROLLING THE STRUCTURE OF GENERATED SERVLETS: THE JSP PAGE DIRECTIVE......Page 386
12.1 The import Attribute......Page 387
12.2 The contentType and pageEncoding Attributes......Page 390
12.3 Conditionally Generating Excel Spreadsheets......Page 392
12.4 The session Attribute......Page 395
12.6 The buffer and autoFlush Attributes......Page 396
12.8 The errorPage and isErrorPage Attributes......Page 397
12.9 The isThreadSafe Attribute......Page 400
12.11 The language Attribute......Page 402
12.12 XML Syntax for Directives......Page 403
CHAPTER 13 INCLUDING FILES AND APPLETS IN JSP PAGES......Page 406
13.1 Including Pages at Request Time: The jsp:include Action......Page 407
13.2 Including Files at Page Translation Time: The include Directive......Page 413
13.4 Including Applets for the Java Plug-In......Page 419
CHAPTER 14 USING JAVABEANS COMPONENTS IN JSP DOCUMENTS......Page 432
14.2 What Are Beans?......Page 433
14.3 Using Beans: Basic Tasks......Page 435
14.4 Example: StringBean......Page 439
14.5 Setting Bean Properties: Advanced Techniques......Page 442
14.6 Sharing Beans......Page 450
14.7 Sharing Beans in Four Different Ways: An Example......Page 454
15.1 Understanding the Need for MVC......Page 468
15.2 Implementing MVC with RequestDispatcher......Page 470
15.3 Summarizing MVC Code......Page 476
15.4 Interpreting Relative URLs in the Destination Page......Page 478
15.5 Applying MVC: Bank Account Balances......Page 479
15.6 Comparing the Three Data-Sharing Approaches......Page 486
15.7 Forwarding Requests from JSP Pages......Page 495
15.8 Including Pages......Page 496
16.1 Motivating EL Usage......Page 498
16.2 Invoking the Expression Language......Page 500
16.3 Preventing Expression Language Evaluation......Page 501
16.4 Preventing Use of Standard Scripting Elements......Page 504
16.5 Accessing Scoped Variables......Page 505
16.6 Accessing Bean Properties......Page 508
16.7 Accessing Collections......Page 514
16.8 Referencing Implicit Objects......Page 516
16.9 Using Expression Language Operators......Page 520
16.10 Evaluating Expressions Conditionally......Page 524
16.11 Previewing Other Expression Language Capabilities......Page 528
PART III: SUPPORTING TECHNOLOGY......Page 530
CHAPTER 17 ACCESSING DATABASES WITH JDBC......Page 532
17.1 Using JDBC in General......Page 533
17.2 Basic JDBC Examples......Page 542
17.3 Simplifying Database Access with JDBC Utilities......Page 550
17.4 Using Prepared Statements......Page 563
17.5 Creating Callable Statements......Page 567
17.6 Using Database Transactions......Page 574
17.7 Mapping Data to Objects by Using ORM Frameworks......Page 579
CHAPTER 18 CONFIGURING MS ACCESS, MYSQL, AND ORACLE9I......Page 588
18.1 Configuring Microsoft Access for Use with JDBC......Page 589
18.2 Installing and Configuring MySQL......Page 593
18.3 Installing and Configuring Oracle9i Database......Page 596
18.4 Testing Your Database Through a JDBC Connection......Page 623
18.5 Setting Up the music Table......Page 632
CHAPTER 19 CREATING AND PROCESSING HTML FORMS......Page 640
19.1 How HTML Forms Transmit Data......Page 641
19.2 The FORM Element......Page 646
19.3 Text Controls......Page 653
19.4 Push Buttons......Page 658
19.5 Check Boxes and Radio Buttons......Page 664
19.6 Combo Boxes and List Boxes......Page 667
19.7 File Upload Controls......Page 672
19.8 Server-Side Image Maps......Page 674
19.9 Hidden Fields......Page 679
19.10 Groups of Controls......Page 680
19.11 Tab Order Control......Page 682
19.12 A Debugging Web Server......Page 683
Tomcat......Page 692
JRun......Page 696
Resin......Page 700
B......Page 704
C......Page 705
D......Page 707
F......Page 708
G......Page 709
H......Page 710
J......Page 712
M......Page 716
O......Page 717
R......Page 719
S......Page 720
V......Page 723
Z......Page 724

Polecaj historie