Web Development with JavaServer Pages

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Dynamic content-personalized, customized, and up-to-the-minute-is a key component of site development on the World Wide Web today. Java Server Pages (JSP) is a new server-side technology for generating dynamic content in Web pages and other on-line applications. This guide to JSP covers all aspects of development for the new versions of the JSP and Servlet specifications (1.2 and 2.3, respectively). The many new features introduced in these versions are discussed, including servlet filters and enhancements to the API for JSP Tag Libraries. The interaction between JSP and other J2EE technologies, such as Enterprise JavaBeans, are also covered, as are comparisons to similar dynamic content systems including CGI, Active Server Pages, Cold Fusion, and PHP.

Author(s): Duane K. Fields, Mark A. Kolb, Shawn Bayern
Edition: 2nd
Publisher: Manning
Year: 2001

Language: English
Pages: 800

brief contents......Page 7
contents......Page 9
preface to the second edition......Page 25
preface to the first edition......Page 29
acknowledgments......Page 31
about this book......Page 33
about the authors......Page 38
authors online......Page 39
about the cover illustration......Page 40
Introduction......Page 41
1.2 Dynamic content on the web......Page 42
1.2.1 Why dynamic content?......Page 43
1.2.2 Common Gateway Interface......Page 44
1.2.3 Template systems......Page 45
1.2.4 Java on the Web......Page 48
1.2.5 How XML fits in......Page 51
1.3.1 The JavaBeans component architecture......Page 53
1.3.2 JSP and Java 2 Platform Enterprise Edition......Page 55
HTTP and servlets......Page 57
2.1.1 HTTP basics......Page 58
2.1.2 GET versus POST......Page 61
2.2 Java servlets......Page 63
2.2.2 The anatomy of a servlet......Page 64
2.2.3 A servlet example......Page 66
First steps......Page 70
3.1 Simple text......Page 71
3.2 Dynamic content......Page 72
3.2.1 Conditional logic......Page 73
3.2.2 Iteration......Page 74
3.2.3 Non-HTML output......Page 77
3.3.1 Accessing request parameters......Page 78
3.3.2 Using sessions......Page 79
3.4 Separating logic from presentation......Page 81
3.4.1 Reusing logic with JavaBeans......Page 82
3.4.2 Abstracting logic with custom tags......Page 84
3.5 Review of examples......Page 85
How JSP works......Page 86
4.1.1 Directives and scripting elements......Page 87
4.1.2 Standard and custom actions......Page 88
4.2.1 Translation to servlets......Page 92
4.2.2 Translation versus execution......Page 94
4.3.1 Automatic servlet generation......Page 96
4.3.2 Buffered output......Page 97
4.3.3 Session management......Page 99
4.3.4 Exception handling......Page 103
4.3.6 Support for JavaBeans and HTML forms......Page 104
Programming JSP scripts......Page 105
5.1 Scripting languages......Page 106
5.3.1 Page directive......Page 108
5.3.2 Include directive......Page 120
5.3.3 Tag library directive......Page 122
5.4 Scripting elements......Page 123
5.4.1 Declarations......Page 124
5.4.2 Expressions......Page 128
5.4.3 Scriptlets......Page 131
5.5.1 Conditionalization......Page 133
5.5.3 Exception handling......Page 134
5.6 Comments......Page 137
5.6.2 JSP comments......Page 138
5.6.3 Scripting language comments......Page 139
Actions and implicit objects......Page 141
6.1 Implicit objects......Page 142
6.1.1 Servlet-related objects......Page 144
6.1.2 Input/Output......Page 145
6.1.3 Contextual objects......Page 152
6.1.4 Error handling......Page 160
6.2 Actions......Page 161
6.2.1 Forward......Page 162
6.2.2 Include......Page 165
6.2.4 Bean tags......Page 168
Using JSP components......Page 169
7.1.1 Component architectures......Page 170
7.1.2 Benefits of a component architecture......Page 171
7.1.3 Component design for web projects......Page 172
7.1.4 Building applications from components......Page 173
7.2 JavaBean fundamentals......Page 175
7.2.1 The different types of JavaBeans......Page 178
7.3.1 Tag-based component programming......Page 180
7.3.2 Accessing JSP components......Page 182
7.3.3 Initializing beans......Page 190
7.3.4 Controlling a bean’s scope......Page 197
Developing JSP components......Page 205
8.1.1 Bean conventions......Page 206
8.1.2 The bean constructor......Page 207
8.1.3 Defining a bean’s properties......Page 208
8.1.4 Indexed properties......Page 212
8.1.5 Implementing bean properties as cursors......Page 216
8.1.6 Boolean properties......Page 218
8.1.7 JSP type conversion......Page 219
8.1.8 Configuring beans......Page 221
8.2.1 Example: a TimerBean......Page 222
8.2.2 A bean that calculates interest......Page 224
8.3.1 The BeanInfo interface......Page 229
8.3.3 The HttpSessionBindingListener interface......Page 230
8.3.4 Other features of the Bean API......Page 231
8.4.1 Accessing beans through scriptlets......Page 232
8.4.2 Accessing scriptlet created objects......Page 233
Working with databases......Page 238
9.1 JSP and JDBC......Page 239
9.1.1 JNDI and data sources......Page 240
9.1.2 Prepared statements......Page 241
9.2.1 Creating JSP components from table data......Page 242
9.2.2 JSPs and JDBC data types......Page 245
9.2.3 Maintaining persistent connections......Page 248
9.2.4 Handling large sets of results......Page 251
9.2.5 Transaction processing......Page 256
9.3.1 Project overview......Page 257
9.3.3 Design overview......Page 258
Architecting JSP applications......Page 269
10.1 Web applications......Page 270
10.1.1 Web application flow......Page 272
10.2.1 Role-based pages......Page 273
10.2.2 Managing page flow with action targets......Page 276
10.2.3 Building composite pages......Page 278
10.2.4 Limitations of the page-centric approach......Page 281
10.3 Servlet-centric design......Page 282
10.3.1 Hello, World—with servlets......Page 283
10.3.2 JSP and the servlet API......Page 284
10.3.3 Servlets for application control......Page 287
10.3.4 Servlets for handling application logic......Page 288
10.3.5 Servlets as single entry points......Page 289
10.3.6 Handling errors in the servlet......Page 292
10.3.7 Example: servlet-centric employee browser......Page 293
10.3.8 EmployeeBean......Page 295
10.3.9 FetchEmployeeServlet......Page 298
10.3.10 JSP employee list......Page 301
10.3.11 JSP page viewer......Page 302
10.4.1 What are Enterprise JavaBeans?......Page 303
10.4.3 Application servers and EJB containers......Page 304
10.4.4 Application design with EJBs......Page 305
10.5 Choosing an appropriate architecture......Page 306
10.5.1 Application environment......Page 307
10.5.2 Enterprise software requirements......Page 308
10.5.4 Technical considerations......Page 309
10.5.5 Organizational considerations......Page 310
An example JSP project......Page 312
11.1.2 Application requirements......Page 313
11.1.3 Application modules......Page 315
11.1.4 Building an FAQ component......Page 316
11.2 The storage module......Page 318
11.2.2 The FaqRepository class......Page 319
11.2.3 Storage module exceptions......Page 325
11.3 The administration module......Page 326
11.3.1 The administration servlet......Page 327
11.3.2 The main menu......Page 333
11.3.3 Adding an FAQ......Page 337
11.3.4 Deleting an FAQ......Page 340
11.3.5 Updating an FAQ......Page 346
11.4 The web access module......Page 351
11.4.1 The FaqServlet......Page 352
11.4.2 Viewing a single FAQ......Page 353
11.4.3 Viewing all the FAQs......Page 354
11.4.4 A table of contents view......Page 355
11.4.5 Plain text view......Page 357
Introducing filters and listeners......Page 358
12.1.1 Session listeners......Page 359
12.1.2 Application listeners......Page 364
12.2 Filters......Page 366
12.2.1 How filters work......Page 367
12.2.2 Filter classes......Page 370
12.2.3 Wrapper classes......Page 372
12.3 Using filters and listeners......Page 373
Applying filters and listeners......Page 374
13.1 Application description......Page 375
13.2.1 User account representation......Page 377
13.2.2 User management interface......Page 378
13.2.3 User management implementation......Page 379
13.3.1 Session interactions......Page 381
13.3.2 Login servlet......Page 384
13.3.3 Login pages......Page 390
13.3.4 Content pages......Page 393
13.3.5 Logout servlet......Page 397
13.3.6 Logout pages......Page 398
13.4 Access control filters......Page 400
13.4.1 Authentication filter......Page 401
13.4.2 Role filter......Page 404
13.5 Logging listener......Page 408
13.5.2 HttpSessionAttributeListener methods......Page 409
13.6 Content filter......Page 412
13.6.1 Filter methods......Page 413
13.6.2 Response wrapper inner class......Page 415
13.6.3 Output stream inner class......Page 416
13.6.4 More filter methods......Page 417
13.6.5 Filter results......Page 420
13.6.6 Other content filters......Page 421
Deploying JSP applications......Page 424
14.1 This means WAR......Page 425
14.1.1 WAR is XML......Page 426
14.1.2 Waging WAR......Page 429
14.2.1 WAR materiel......Page 430
14.2.2 Drafting deployment descriptors......Page 436
14.3 Maintaining a WAR footing......Page 455
Performing common JSP tasks......Page 458
15.1.1 Managing cookies......Page 459
15.1.2 The Cookie class......Page 460
15.1.3 Example 1: setting a cookie......Page 461
15.1.4 Example 2: retrieving a cookie......Page 462
15.2 Creating error pages......Page 465
15.2.1 An erroneous page......Page 466
15.2.2 Data collection methods......Page 467
15.2.3 Sending electronic mail......Page 472
15.2.4 The error page......Page 473
15.3 Mixing JSP and JavaScript......Page 477
15.4.1 Sticky widgets......Page 481
15.4.2 Utility methods......Page 482
15.4.3 The example form......Page 483
15.4.4 Setting up the form......Page 485
15.4.5 Text and hidden fields......Page 486
15.4.7 Radio buttons......Page 487
15.4.9 Check boxes......Page 488
15.4.10 Form source......Page 489
15.5.1 Client- and server-side validation......Page 491
15.5.2 Example: server-side validation......Page 492
15.6 Building a shopping cart......Page 498
15.6.1 Overview......Page 499
15.6.3 ShoppingCartItem and InventoryManager......Page 500
15.6.4 The ShoppingCart bean......Page 504
15.6.5 Displaying the shopping cart......Page 506
15.7.1 Determining the last modification date......Page 507
15.7.2 Executing system commands......Page 508
Generating non-HTML content......Page 510
16.1.1 The importance of MIME......Page 511
16.1.3 Detecting your client......Page 512
16.1.4 Designing multiformat applications......Page 513
16.1.5 Controlling the file extension......Page 514
16.2.1 Plain text output......Page 515
16.2.2 WYGIWYG output (what you generate is what you get)......Page 516
16.3 XML documents......Page 517
16.3.1 Creating voice XML documents......Page 519
16.4 External content......Page 522
16.4.1 JSP style sheets......Page 523
16.4.2 JavaScript......Page 525
16.5 Advanced content formats......Page 527
16.5.1 Excel spread sheets......Page 528
16.5.2 Code generation......Page 529
JSP by example......Page 533
17.1.1 The BannerBean......Page 534
17.1.2 Using the bean......Page 535
17.2.1 The QuoteBean......Page 537
17.2.2 Using the bean......Page 538
17.3 The Tell a Friend! sticker......Page 539
17.3.1 The sticker......Page 540
17.3.2 The MailForm page......Page 542
17.3.3 Sending the mail......Page 543
17.4.1 The Whois protocol......Page 545
17.4.3 The WhoisBean......Page 547
17.4.4 Building the front end......Page 555
17.5 An index generator......Page 557
17.5.1 A basic implementation......Page 558
17.5.2 An improved version......Page 560
17.6.1 Displaying the source......Page 565
17.6.3 Adding a view source button to a page......Page 567
17.6.4 Viewing source through a bookmark......Page 568
Creating custom tags......Page 569
18.1 Role of custom tags......Page 570
18.2 How tag libraries work......Page 571
18.3.1 Library elements......Page 575
18.3.2 Validator elements......Page 577
18.3.4 Tag elements......Page 578
18.3.5 Variable elements......Page 580
18.3.6 Attribute elements......Page 581
18.3.7 Example element......Page 583
18.4.1 Tag handlers......Page 584
18.4.2 Tag handler life-cycle......Page 590
18.4.3 Helper classes......Page 596
18.5 Example tag library......Page 599
18.6 Content substitution......Page 600
18.7 Tag attributes......Page 603
18.8 Content translation......Page 607
18.8.1 URL rewriting......Page 608
18.8.2 HTML encoding......Page 612
18.9 Exception handling......Page 615
18.10 To be continued......Page 620
Implementing advanced custom tags......Page 622
19.1.1 Example tag......Page 623
19.1.2 Scripting variable JavaBean......Page 625
19.2 Flow of control......Page 627
19.2.1 Conditionalization......Page 628
19.2.2 Iteration......Page 635
19.3 Interacting tags......Page 653
19.3.1 Interaction mechanisms......Page 654
19.3.2 Index tag......Page 656
19.4 The final ingredient......Page 659
Validating custom tag libraries......Page 661
20.1 Two representations of JSP......Page 662
20.2 JSP pages as XML documents......Page 664
20.2.1 The root element......Page 665
20.2.2 Template text......Page 666
20.2.4 Request-time attribute values......Page 667
20.2.6 Sample page......Page 669
20.3 Tag library validation......Page 671
20.4 Example validators......Page 674
20.4.1 Copying validator......Page 675
20.4.2 Script-prohibiting validator......Page 678
20.4.3 Error handling......Page 682
20.4.4 Content handler......Page 685
20.4.5 Nesting validator......Page 691
20.5 Packaging the tag library......Page 700
20.5.1 Packaging a single library......Page 701
20.5.2 Packaging multiple libraries......Page 702
20.6 For further information......Page 706
A.1 Introduction......Page 709
A.2.3 XML syntax now fully supported......Page 710
A.2.8 Flush on include no longer required......Page 711
A.3.5 Dependency on installed extensions......Page 712
A.4.3 Changes to the TLD......Page 713
A.6 New servlet features......Page 714
A.6.2 Application events......Page 715
Running the reference implementation......Page 716
B.2 Downloading and installing Tomcat......Page 717
B.3 Web applications and Tomcat......Page 721
C.1 Browser support for Java......Page 723
C.2.1 Required attributes......Page 725
C.2.2 Optional attributes......Page 727
C.2.3 Parameters......Page 728
C.2.4 Fallback text......Page 729
C.3 Example: applet configuration......Page 730
D.2 JSP-related web sites......Page 737
D.4 JSP containers......Page 738
D.5 Java application servers with JSP support......Page 739
D.8 Mailing lists and newsgroups......Page 740
E.1 Content comments......Page 742
E.2 JSP comments......Page 743
E.3 ......Page 744
E.4 ......Page 745
E.5 ......Page 746
E.6 ......Page 747
E.7 ......Page 748
E.8 ......Page 749
E.9 ......Page 750
E.10 ......Page 751
E.11 ......Page 752
E.12 ......Page 753
E.13 ......Page 754
E.14 ......Page 755
JSP API reference......Page 758
F.2.2 Interface FilterChain†......Page 759
F.2.5 Interface RequestDispatcher......Page 760
F.2.8 Interface ServletContext......Page 761
F.2.11 Interface ServletContextEvent†......Page 762
F.2.14 Class ServletInputStream......Page 763
F.2.16 Interface ServletRequest......Page 764
F.2.17 Class ServletRequestWrapper†......Page 765
F.2.19 Class ServletResponseWrapper†......Page 766
F.3.1 Class cookie......Page 767
F.3.2 Class HttpServlet......Page 768
F.3.3 Interface HttpServletRequest......Page 769
F.3.5 Interface HttpServletResponse......Page 770
F.3.6 Class HttpServletResponseWrapper†......Page 772
F.3.9 Interface HttpSessionAttributeListener†......Page 773
F.3.12 Class HttpSessionEvent†......Page 774
F.4.1 Interface HttpJspPage......Page 775
F.4.4 Class JspFactory......Page 776
F.4.7 Class JspWriter......Page 777
F.4.8 Class PageContext......Page 778
F.5.3 Class BodyTagSupport......Page 780
F.5.6 Interface Tag......Page 781
F.5.8 Class TagData......Page 782
F.5.10 Class TagInfo......Page 783
F.5.13 Class TagSupport......Page 784
F.5.16 Class VariableInfo......Page 785
index......Page 787