Prentice Hall - Advanced Javaserver Pages (Servlet 2.2 And Jsp 1.1) - 2001 - David M. Geary.pdf

(6811 KB) Pobierz
Advanced JavaServer Pages
1002314.001.png
Advanced JavaServer Pages
David M. Geary
Publisher: Prentice Hall PTR
First Edition May 01, 2001
ISBN: 0-13-030704-1, 508 pages
To fully exploit the power of JavaServer Pages technology in Web application development,
based on J2EE technology, you need to master the sophisticated server-side techniques that
David Geary presents in Advanced JavaServer Pages .
Advanced JavaServer Pages features detailed chapters on internationalization, authentication,
JSP technology templates, design, and XML. It concludes with a comprehensive case study
that ties together key topics developed in the book and demonstrates how to integrate
advanced techniques based on JSP technology. This book is a must-have resource for every
developer of Java technology creating server-side applications with JSP technology and
servlets.
Advanced JavaServer Pages
Table of Contents
Table of Contents ................................................................................................................. 1
Preface ................................................................................................................................... 1
What This Book Is About................................................................................................... 1
The Servlet and JSP APIs This Book Depends Upon ........................................................ 2
How This Book's Code Was Tested ................................................................................... 2
This Book's Audience......................................................................................................... 2
How This Book Was Written ............................................................................................. 2
How To Use This Book...................................................................................................... 3
This Book's Custom Tag Libraries..................................................................................... 3
This Book's Code ............................................................................................................... 3
Conventions Used in This Book......................................................................................... 4
Acknowledgments.................................................................................................................5
Chapter 1. CUSTOM TAG FUNDAMENTALS............................................................... 6
Using Custom Tags—The JSP File.................................................................................... 8
Defining Custom Tags—The TLD .................................................................................... 9
Implementing Custom Tags—Tag Handlers.................................................................... 10
Specifying the TLD in WEB-INF/web.xml ..................................................................... 12
<taglib> and <tag> ........................................................................................................... 13
The Tag Life Cycle .......................................................................................................... 14
Thread Safety ................................................................................................................... 15
Tags with Attributes ......................................................................................................... 16
Accessing Page Information............................................................................................. 20
Error Handling.................................................................................................................. 22
The Tag Package .............................................................................................................. 23
Tags with Bodies .............................................................................................................. 26
Conclusion........................................................................................................................ 28
Chapter 2. CUSTOM TAG ADVANCED CONCEPTS................................................. 29
Body Tag Handlers........................................................................................................... 30
Iteration ............................................................................................................................ 32
Scripting Variables ........................................................................................................... 36
Body Content.................................................................................................................... 40
Nested Tags ...................................................................................................................... 50
Conclusion........................................................................................................................ 52
Chapter 3. HTML FORMS ............................................................................................... 53
Forms with Beans............................................................................................................. 53
Validation ......................................................................................................................... 60
A Form Framework .......................................................................................................... 67
Custom Tags..................................................................................................................... 80
Conclusion........................................................................................................................ 81
Chapter 4. TEMPLATES .................................................................................................. 83
Encapsulating Layout ....................................................................................................... 84
Optional Content .............................................................................................................. 88
Role-based Content .......................................................................................................... 91
Defining Regions Separately............................................................................................ 92
Nesting Regions ............................................................................................................... 94
Extending Regions ........................................................................................................... 96
Combining Features ......................................................................................................... 98
Region Tag Implementations ......................................................................................... 100
Advanced JavaServer Pages
Conclusion...................................................................................................................... 111
Chapter 5. DESIGN ......................................................................................................... 112
Model 1 .......................................................................................................................... 112
Model 2: An MVC Approach......................................................................................... 114
A Model 2 Example ....................................................................................................... 115
Conclusion...................................................................................................................... 127
Chapter 6. A MODEL 2 FRAMEWORK ...................................................................... 128
A Model 2 Framework ................................................................................................... 128
Refining the Design........................................................................................................ 136
Adding Use Cases .......................................................................................................... 141
The Importance of Custom Tags .................................................................................... 145
JSP Scripts...................................................................................................................... 146
Conclusion...................................................................................................................... 149
Chapter 7. EVENT HANDLING AND SENSITIVE FORM RESUBMISSIONS..... 151
Event Handling for a Model 2 Framework .................................................................... 151
Sensitive Form Resubmissions....................................................................................... 156
Conclusion...................................................................................................................... 169
Chapter 8. I18N ................................................................................................................ 170
Unicode .......................................................................................................................... 170
Charsets .......................................................................................................................... 172
Locales ........................................................................................................................... 174
Resource Bundles ........................................................................................................... 176
Multiple Resource Bundles ............................................................................................ 183
Formatting Locale-Sensitive Information ...................................................................... 185
Browser Language Preferences ...................................................................................... 192
Custom Tags................................................................................................................... 195
Conclusion...................................................................................................................... 204
Chapter 9. SECURITY .................................................................................................... 205
Servlet Authentication.................................................................................................... 205
Basic Authentication ...................................................................................................... 209
Digest Authentication..................................................................................................... 211
Form-Based Authentication ........................................................................................... 212
SSL and Client Certificate Authentication..................................................................... 215
Customizing Authentication........................................................................................... 215
Web Application Security Elements .............................................................................. 220
Programmatic Authentication ........................................................................................ 221
Conclusion...................................................................................................................... 231
Chapter 10. DATABASES............................................................................................... 232
Database Creation .......................................................................................................... 233
Data Sources................................................................................................................... 235
Database Custom Tags ................................................................................................... 235
Connection Pooling ........................................................................................................ 247
Prepared Statements ....................................................................................................... 256
Transactions ................................................................................................................... 262
Scrolling Through Result Sets........................................................................................ 265
Conclusion...................................................................................................................... 269
Chapter 11. XML ............................................................................................................. 271
Generating XML ............................................................................................................ 272
Postprocessing XML ...................................................................................................... 278
Parsing XML .................................................................................................................. 279
Advanced JavaServer Pages
Transforming XML ........................................................................................................ 308
Using XPath ................................................................................................................... 316
Conclusion...................................................................................................................... 320
Chapter 12. A CASE STUDY.......................................................................................... 321
The Fruitstand ................................................................................................................ 322
The Model 2 Framework................................................................................................ 341
Internationalization......................................................................................................... 359
Authentication ................................................................................................................ 363
HTML Forms ................................................................................................................. 373
Sensitive Form Resubmissions....................................................................................... 379
SSL ................................................................................................................................. 380
XML and DOM .............................................................................................................. 381
Conclusion...................................................................................................................... 384
Appendix SERVLET FILTERS ..................................................................................... 385
A Servlet Filter Example................................................................................................ 386
Conclusion...................................................................................................................... 389
Zgłoś jeśli naruszono regulamin