Art of Java Web Development P1

Chia sẻ: Tan Giang | Ngày: | Loại File: PDF | Số trang:30

0
97
lượt xem
10
download

Art of Java Web Development P1

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

In ancient China (approximately 500 B.C.), Sun Tzu wrote The Art of War. In it, he described the state of the art in warfare. The book took a universal approach, describing wide-ranging topics that related to one another only through how they applied to warfare. In 1961, Julia Child published the classic Mastering the Art of French Cooking. In her book, she described the essentials of mastering French cooking. Her book covered an extensive array of topics, including both kitchen techniques and recipes....

Chủ đề:
Lưu

Nội dung Text: Art of Java Web Development P1

  1. ART OF JAVA WEB DEVELOPMENT STRUTS TAPESTRY COMMONS VELOCITY Neal Ford JUNIT AXIS COCOON INTERNETBEANS WEBWORK MANNING
  2. Art of Java Web Development
  3. Art of Java Web Development STRUTS, TAPESTRY, COMMONS, VELOCITY, JUNIT, AXIS, COCOON, INTERNETBEANS, WEBWORK NEAL FORD MANNING Greenwich (74° w. long.)
  4. For online information and ordering of this and other Manning books, go to www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. 209 Bruce Park Avenue Fax: (203) 661-9018 Greenwich, CT 06830 email: orders@manning.com ©2004 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books they publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Liz Welch 209 Bruce Park Avenue Typesetter: Dottie Marsico Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN: 1-932394-06-0 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – VHG – 08 07 06 05 04 03
  5. To Chuck, who still teaches me stuff daily
  6. brief contents PART I THE EVOLUTION OF WEB ARCHITECTURE AND DESIGN ....................................................... 1 1 I State-of-the-art web design 3 2 I Building web applications 27 3 I Creating custom JSP tags 61 4 I The Model 2 design pattern 91 PART II WEB FRAMEWORKS ........................................ 131 5 I Using Struts 133 6 I Tapestry 159 7 I WebWork 199 8 I InternetBeans Express 227 9 I Velocity 261 10 I Cocoon 283 11 I Evaluating frameworks 311 vii
  7. viii BRIEF CONTENTS PART III BEST PRACTICES ............................................ 327 12 I Separating concerns 329 13 I Handling flow 371 14 I Performance 409 15 I Resource management 445 16 I Debugging 475 17 I Unit testing 521 18 I Web services and Axis 543 19 I What won’t fit in this book 563
  8. contents preface xvii acknowledgments xix about the book xxi about the cover illustration xxx PART I THE EVOLUTION OF WEB ARCHITECTURE AND DESIGN ....................................................... 1 1 State-of-the-art web design 1.1 3 A brief history of Java web development 4 1.2 The importance of design patterns 6 The Model-View-Controller design pattern 7 I The emergence of Model 2 9 Evolution 10 I 1.3 Using frameworks 11 A flavor of the Struts framework 12 A flavor of the Turbine I framework 14 Objectively choosing a framework 20 I 1.4 Best practices 20 Business rules 20 Where should the rules reside? I 22 Leveraging best practices 24 1.5 Summary 25 ix
  9. x CONTENTS 2 Building web applications 2.1 27 Building web applications with servlets The eMotherEarth servlet application 29 29 Evaluating the servlet approach 50 2.2 Building web applications with JSP 50 The JSP eMotherEarth application 51 Evaluating the JSP approach 59 2.3 Summary 60 3 Creating custom JSP tags 3.1 The case for custom tags 61 62 3.2 The tag interfaces 63 The Tag interface 63 The IterationTag interface I 64 The BodyTag interface 65 3.3 Building simple tags 66 The HtmlSqlResult tag 66 I Registering the tag 71 3.4 Validating tag attributes 75 Adding DbPool to the application tag 75 3.5 Using prebuilt tags 80 Using JSTL 81 I Using other taglibs 84 3.6 Custom tag considerations 86 Resource usage 87 I Building a framework 88 3.7 Now that we’re here, where are we? 88 3.8 Summary 89 4 The Model 2 design pattern 4.1 Using Model 2 as your framework The Model 2 schedule application 91 93 92 Options in Model 2 116 4.2 Parameterizing commands with controller servlets 117 An example of parameterizing commands 118 Advantages and disadvantages 127 4.3 Summary 128
  10. CONTENTS xi PART II WEB FRAMEWORKS ........................................ 131 5 Using Struts 5.1 133 Building Model 2 Web applications with Struts The Struts schedule application 134 Value objects as form I 134 beans 136 Objectifying commands with Struts’ actions 137 I Configuring Struts applications 139 Using Struts’ custom tags I to simplify JSP 142 Internationalization with Struts 145 I Struts’ support for data entry 147 Declarative validations 151 I 5.2 Evaluating Struts 156 5.3 Summary 157 6 Tapestry 159 6.1 Overview 160 6.2 The architecture 160 6.3 A simple Tapestry application 162 Tapestry Hello, World 162 6.4 The Tapestry framework 167 Framework classes and interfaces 167 I Components 170 6.5 Scheduling in Tapestry 173 Bootstrapping the application 173 The Home page 176 I The custom table component 180 The Add page 185 I 6.6 Evaluating Tapestry 192 Documentation and samples 192 I Debugging support 195 Using Tapestry 196 6.7 Summary 197 7 WebWork 7.1 Overview 199 200 The architecture 201 I The configuration 202 7.2 Key concepts 203 Actions 204 Key interfaces 204 The value stack I I 205 Expression language 206 BeanInfo classes 207 I Templates 207
  11. xii CONTENTS 7.3 Scheduling in WebWork 208 The configuration 208 The View page 209 I The Add page 214 Validations 220 I 7.4 Evaluating WebWork 224 7.5 Summary 226 8 InternetBeans Express 8.1 Overview 228 227 8.2 The architecture 230 DataExpress 230 I InternetBeans Express 233 8.3 InternetBeans Express components 234 ixPageProducer 234 I ixComponents 236 8.4 Scheduling with InternetBeans 237 Data connectivity 238 The View page 242 I I The Add page 245 Validations 249 I 8.5 JSP custom tags 255 8.6 Evaluating InternetBeans Express 257 Documentation and samples 257 Using InternetBeans Express 258 8.7 Summary 259 9 Velocity 261 9.1 Overview 262 9.2 The architecture 263 9.3 Key concepts 265 Setting up Velocity 265 The Velocity Template I Language 268 Context 269 I 9.4 Scheduling with Velocity 269 The View page 271 I The Add page 274 Validations 278
  12. CONTENTS xiii 9.5 Evaluating Velocity 281 Documentation and samples 281 I Using Velocity 282 9.6 Summary 282 10 Cocoon 10.1 283 Overview 284 10.2 The architecture 285 The publishing framework 285 I The web framework 288 10.3 Key concepts 289 The publishing framework 289 I The sitemap 295 The web framework 299 10.4 Scheduling in Cocoon 302 The sitemap 303 I The action 304 I The view 305 10.5 Evaluating Cocoon 307 Documentation and samples 307 I Source code 308 Debugging 308 10.6 Summary 309 11 Evaluating frameworks 11.1 Evaluation criteria 311 312 Suitability to the application 312 Documentation 315I Source code 316 Tool support 317 External criteria I I 318 11.2 Design considerations 319 Adherence to good design principles 319 The user I interface 320 Innovative features 321 I Insularity 322 “Feel” 322 I 11.3 What I like 323 Transparent infrastructure 323 Innovative ideas I 323 Ultra-high cohesion and low coupling 324 Evaluating frameworks as a hobby 324 11.4 Summary 324
  13. xiv CONTENTS PART III BEST PRACTICES ............................................ 327 12 Separating concerns 12.1 329 Using interfaces to hide implementation JDBC interfaces 331 Interfaces in frameworks I 330 331 Decoupled classes 332 12.2 Using JavaBeans 333 Model beans 334 12.3 Using Enterprise JavaBeans 337 The EJB architecture 338 Porting from JavaBeans to Enterprise I JavaBeans 340 Using EJBs in web frameworks 360 I Managing JNDI context 361 12.4 Performing validations with model beans 362 Client-side validations 362 Building client-side validations from the server 365 12.5 Summary 368 13 Handling flow 13.1 371 Application usability options 372 Building the base: eMotherEarth.com 372 Page-at-a-time I scrolling 378 Sortable columns 384 I User interface techniques in frameworks 389 13.2 Building undo operations 390 Leveraging transaction processing 391 Using the Memento I design pattern 394 Undo in frameworks 401 I 13.3 Using exception handling 401 The difference between technical and domain exceptions 401 Creating custom exception classes 402 Where to catch and I handle exceptions 403 Exceptions in frameworks 406 I 13.4 Summary 407 14 Performance 409 14.1 Profiling 410 Measuring memory 410 Performance profiling 412 I Load testing 419 I Performance of profiling frameworks 421
  14. CONTENTS xv 14.2 Common performance pitfalls 421 Object creation 422 I Extraneous object references 424 String usage 426 14.3 Pooling 427 Simple object pools 427 Soft and weak references 428 I Commons pools 433 Pooling in frameworks 440 I 14.4 Designing for scalability 440 When to scale up to EJB 441 Molding your architecture for the future 441 14.5 When to optimize 442 14.6 Summary 443 15 Resource management 445 15.1 Caching strategies 446 Caching with the Flyweight design pattern 447 Caching with I the Façade design pattern 453 Resource management I in frameworks 469 15.2 Other resources you need to manage 470 Effectively using JNDI 470 Using lazy instantiation I 472 Working with web collections 472 15.3 Summary 473 16 Debugging 16.1 475 Debugging web applications 476 16.2 Debugging with the SDK 483 Starting the debugger 483 I Running the debugger 486 Breakpoints and steps 489 I Accessing variables 490 Effectively using jdb 492 16.3 Debugging with IDEs 493 Debugging with NetBeans 493 Debugging with JBuilder 498 I Differences between debuggers 502 16.4 Evaluating debuggers 505 16.5 Debugging in frameworks 506 Struts 506 Tapestry 507 WebWork 507 I I InternetBeans Express 507 Velocity 508 Cocoon I I 508
  15. xvi CONTENTS 16.6 Logging 508 General logging concepts 509 SDK logging 512 I log4j logging 516 Choosing a logging framework 519 I Logging in frameworks 519 16.7 Summary 520 17 Unit testing 17.1 521 The case for testing Agile development 522 522 I Unit testing in web applications 524 17.2 Unit testing and JUnit 525 Test cases 525 I Testing entities 525 Running tests 528 I Test suites 529 I Testing boundaries 530 Tool support 534 I 17.3 Web testing with JWebUnit 536 JWebUnit TestCases 537 I Testing complex elements 539 17.4 Summary 541 18 Web services and Axis 18.1 Key concepts 544 543 18.2 Axis 545 Architecture of Axis 546 I Axis tools 547 18.3 Calling web services 551 18.4 eMotherEarth web services 553 Configuration 553 I Orders 556 I Calling the web service 559 18.5 Summary 562 19 What won’t fit in this book 19.1 Persistence 564 563 Plain old Java objects 564 Enterprise JavaBeans 564 I Java data objects (JDO) 565 Hibernate 566 I 19.2 HTML and the user interface 566 HTML/XHTML 567 I Cascading Style Sheets 567 19.3 JavaScript 568 19.4 Summary 569 bibliography 570 index 571
  16. preface In ancient China (approximately 500 B.C.), Sun Tzu wrote The Art of War. In it, he described the state of the art in warfare. The book took a universal approach, describing wide-ranging topics that related to one another only through how they applied to warfare. In 1961, Julia Child published the classic Mastering the Art of French Cooking. In her book, she described the essentials of mastering French cooking. Her book covered an extensive array of topics, including both kitchen techniques and recipes. Both of these influential books offered a comprehensive look at the current thinking in their fields. Each covered a variety of topics, discussing specific tech- niques and underlying theories. They included concrete, practical advice, and they talked about the tools available to make the job of warfare (or cooking) easier. Art of Java Web Development strives for the same breadth and depth of coverage for web development in Java. It is not a random selection of topics. Rather, it encom- passes topics that web developers must master to deliver state-of-the-art software. It also examines the evolution of the cutting edge in web development architecture and design, describes the best tools (or weapons) available to developers, and explains specific, practical techniques for improving your web applications. Most development books today fall into one of two categories: API or best prac- tices. The API books focus on a single API, either from J2EE and Java or, for exam- ple, an open-source project. A perfect example is Manning’s excellent Struts in Action, by Ted Husted et al. It takes you through everything you need to know xvii
  17. xviii PREFACE about how to use Struts. The best (or worst) practices books focus on individual topics, examining design patterns and coding samples that represent the best (or worst) ways to perform a certain task. Art of Java Web Development overlaps some of the topics from these other types of books, but it does so in a synergistic manner, discussing how all these pieces (and others) combine to create real-world web applications.
Đồng bộ tài khoản