Tài liệu Struts in Action docx

665 331 1
  • Loading ...
1/665 trang
Tải xuống

Thông tin tài liệu

Ngày đăng: 20/12/2013, 21:16

Struts in Action Struts in Action Building web applications with the leading Java framework Ted Husted Cedric Dumoulin George Franciscus David Winterfeldt MANNING Greenwich (74° w. long.) 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 ©2003 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. The following figures were adapted from other Manning books: figure 2.1 from Swing by Matthew Robinson and Pavel Vorobiev (figure 1.3); figures 2.8, 10.6, 11.1, and 11.2 from Web Development with JavaServer Pages Second Edition by Duane Fields and Mark Kolb (figures 10.1, 10.5, 6.2, and 10.4). Figure 2.9 by Jean-Michel Garnier is reproduced with permission from the Apache Software Foundation. Manning Publications Co. Copyeditor: Liz Welch 32 Lafayette Place Typesetter: Tony Roberts Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1-930110-50-2 Printed in the United States of America 12345678910– VHG – 05 04 03 02 struts_00_a.fm Page iv Tuesday, October 29, 2002 11:14 AM v P ART 1G ETTING STARTED WITH S TRUTS 1 1 ■ Introduction 3 2 ■ Exploring the Struts architecture 29 3 ■ Building a simple application 59 4 ■ Configuring Struts components 105 P ART 2R AISING YOUR FRAMEWORK . 145 5 ■ Coping with ActionForms 147 6 ■ Wiring with ActionForwards 183 7 ■ Designing with ActionMappings 193 8 ■ Working with Action objects 207 9 ■ Extending ActionServlet 255 P ART 3B UILDING YOUR PAGES 265 10 ■ Displaying dynamic content 267 brief contents vi BRIEF CONTENTS 11 ■ Developing applications with Tiles 319 12 ■ Validating user input 365 13 ■ Localizing content 409 14 ■ Using data services with Struts 437 P ART 4S TRUTS BY EXAMPLE . 473 15 ■ Artimus: pulling out the stops 475 16 ■ Redux: migrating to Struts 1.1 533 17 ■ Velocity: replacing JSPs 555 vii contents foreword xix preface xxiii acknowledgments xxvi about this book xxviii P ART 1G ETTING STARTED WITH S TRUTS . 1 1 Introduction 3 1.1 What is this book about? 4 Who makes the Struts software? 4 ■ Why is Struts open source? 5 Why is it called Struts? 5 1.2 What are application frameworks? 5 Other types of frameworks 6 1.3 Enabling technologies 6 Hypertext Transfer Protocol (HTTP) 7 ■ Common Gateway Interface (CGI) 8 ■ Java servlets 9 ■ JavaServer Pages 10 JSP tags 11 ■ JavaBeans 12 ■ Model 2 14 1.4 Struts from 30,000 feet 14 Building a simple application 16 ■ Jump-starting development 16 ■ Where the rubber meets the road 18 Looking back 24 1.5 Summary 28 viii CONTENTS 2 Exploring the Struts architecture 29 2.1 Talking the talk 30 2.2 Why we need Struts 30 One step back, three steps forward 30 ■ Enter Struts 31 Struts controller components 31 ■ Developing a web application with Struts 36 2.3 Why we need frameworks 37 The Web—a never-ending kluge 37 ■ The servlet solution 38 Servlet frameworks 39 ■ The whitebox-blackbox continuum 40 2.4 Struts, Model 2, and MVC 41 The evolution of MVC 41 ■ The rise of Model 2 42 Application layers—decoupling the view 43 How Struts implements Model 2, MVC, and layers 44 2.5 Struts control flow 46 The big picture 47 ■ The finer details 48 Is Struts performant? 52 2.6 The strengths and weaknesses of Struts 53 The weak points 54 ■ Struts’ strong points 56 2.7 Summary 58 3 Building a simple application 59 3.1 Strut by Strut 60 Why a logon application? 61 3.2 Touring a logon application 61 Start here 61 ■ Screens we’ll see 62 ■ The welcome screen 62 The logon screen 62 ■ The welcome screen, again 64 The welcome screen, good-bye 64 ■ Feature roundup 65 3.3 Dissecting the logon application 65 The browser source for the welcome screen 65 ■ The JSP source for the welcome screen 66 ■ The configuration source for the welcome screen 69 ■ The browser source for the logon screen 70 The configuration source for the logon screen 73 The LogonSubmit source 73 ■ The LogonForm source 74 The LogonAction source 77 ■ The LogoffAction source 83 3.4 Constructing an application 86 Defining the requirements 86 ■ Planning the application 87 Planning the source tree 90 ■ Setting up development tools 90 CONTENTS ix Setting up the build.xml file 92 ■ Setting up the web.xml file 92 ■ Setting up the struts-config.xml file 92 Testing the deployment 94 ■ Constructing our welcome page 95 Constructing the logon page 96 ■ Constructing the Constants class 98 ■ Constructing the other classes 99 ■ Creating the user directory 99 ■ Configuring the ActionErrors 100 ■ Compiling and testing the logon page 101 ■ Amending the welcome page 101 ■ The Struts ActionForward Action 102 3.5 Summary 104 4 Configuring Struts components 105 4.1 Three XMLs and a Properties file 106 The rest of the family 106 4.2 The web application deployment descriptor 107 The web.xml file 107 ■ ActionServlet parameters 110 4.3 The Struts configuration 113 Details, details 113 ■ Change management 115 The principle of Protected Variation 115 4.4 The Struts configuration elements 116 <global-exceptions> 118 ■ <form-beans> 119 <global-forwards> 120 ■ <action-mappings> 121 <controller> 123 ■ <message-resources> 123 <plug-in> 124 ■ <data-sources> 125 Rolling your own 126 ■ A skeleton Struts config 127 4.5 The application resources file 128 4.6 The Ant build file 130 4.7 Configuring the Struts core 133 Installing Java and a Java servlet container 133 Installing a development environment 134 Installing the Struts core files 134 4.8 Configuring the Tiles framework 134 4.9 Configuring the Struts Validator 136 4.10 Getting started with the Struts Blank application 137 4.11 Configuring modular applications 139 Divide and conquer 140 ■ Prefixing pages 142 Retrofitting a configuration 142 4.12 Sharing the Struts JAR 142 4.13 Summary 143 [...]... Exploring the business layer 440 Struts bringing your own Model 440 Defining business objects 441 Designing business objects 442 Design consequences 443 Mixing business with Actions (not) 443 A simple example 444 I I I I 14.3 Using ProcessBeans and JDBC with Struts 445 Introducing ProcessBeans 446 ProcessBeans as transfer objects 447 Populating ProcessBeans 448 Executing ProcessBeans 448 Accessing data services... Standard bridge Action classes Standard base Actions 222 8.4 Chaining Actions 228 Starting fresh 229 219 I xi xii CONTENTS 8.5 Scaffold Actions 229 Forward-only Actions 230 I Helper Actions 8.6 Base View Actions 8.7 236 Helper Action techniques 240 239 Optional forwarding 241 Calling ahead 242 Catching chained exceptions 243 Smart error forwarding Confirming success 246 Alternate views 247 Reflecting methods... also worked in the R&D department of a leading international Internet banking company He lives in Lille, France ABOUT THIS BOOK xxxiii George Franciscus is a principal at Nexcel, providing technical and management consulting services in several industries, including telecommunications, banking, life insurance, and property and casualty insurance George has expertise in Java, J2EE, Domino, relational... Reviewing the pages 345 Refactoring a page with 348 Extracting the tags into a Definition 355 Normalizing your base layout 359 Refining your Definitions into base and extended classes 360 Developing a routine 361 Managing the migration 362 I I I I I I 11.6 12 Summary 363 Validating user input 365 12.1 I know it when I see it 366 Input we can’t refuse 366 Web-tier validations Validator... first version of what became the ActionForm was born that weekend, and it turned out to solve a number of interesting design problems In addition, the idea of defining logical names for the presentation and business logic components—and centralizing the definition of those names in a single configuration file—was clearly beneficial in solving the overlapping problems of coordination between the development... links to the Struts material I was writing Then I began adding links to the Struts “extensions” people had started to distribute, and then to the many Struts articles that had begun to appear My Struts Resources page grew larger, and more popular, and so I moved it to the main Struts site It is now a set of several pages with links to everything known about the Struts universe The Struts list remained... unknown ActionMapping 203 I I I I I I I 7.3 Nested components Local forwards 203 203 I Local exceptions 204 7.4 7.5 8 Rolling your own ActionMapping Summary 204 205 Working with Action objects 207 8.1 Ready, set, action! 8.2 Getting it done with Action objects 208 208 What are Actions? 209 When are Actions called? 210 What do Actions do? 211 What does an Action look like? 217 I I 8.3 The standard Actions... /menu/Find 528 /find/Last 530 /menu/Manager 531 I 532 Redux: migrating to Struts 1.1 16.1 533 Next station, Struts 1.1 534 Struts 1.1 feature roundup 16.2 529 I 535 I Features we can use 538 Baseline changes 538 Tiles in Struts 1.1 540 Validator in Struts 1.1 543 ReloadAction in Struts 1.1 544 Other baseline changes to web.xml and struts- config.xml 544 message.jsp (1.1) 545 form.jsp (1.1) 546 MenuCreate... you can reuse the logic in the unaffected tier immediately While all of this intellectual investigation of web application architectures was going on, my professional career was leading me in interesting directions as well I was working for a company that provided information services to the long-haul trucking industry in the United States, and we wanted to expand this service into Europe This created... consequences 157 ActionForms may share names 157 ActionForms may minimize custom code 158 ActionForms may encapsulate helpers 158 ActionForms may nest other beans 158 I I 5.4 ActionForm flavors 160 Map-backed ActionForms 5.5 160 I DynaActionForms 162 Why isn’t an ActionForm 162 Why isn’t an ActionForm just a Map? 163 Why isn’t an ActionForm a plain JavaBean? 163 Why isn’t an ActionForm an interface? 163 . Coping with ActionForms 147 6 ■ Wiring with ActionForwards 183 7 ■ Designing with ActionMappings 193 8 ■ Working with Action objects 207 9 ■ Extending ActionServlet. Struts in Action Struts in Action Building web applications with the leading Java framework Ted Husted Cedric Dumoulin George Franciscus David Winterfeldt
- Xem thêm -

Xem thêm: Tài liệu Struts in Action docx, Tài liệu Struts in Action docx, Tài liệu Struts in Action docx

Từ khóa liên quan

Gợi ý tài liệu liên quan cho bạn