Struts in Action: Building Web Applications with the Leading Java Framework

Free Download

Authors:

ISBN: 9781930110502, 1-930110-50-2

Size: 5 MB (5057014 bytes)

Pages: 664/664

File format:

Language:

Publishing Year:

Category:

Ted Husted, Cedric Dumoulin, George Franciscus, David Winterfeldt, Craig R. McClanahan9781930110502, 1-930110-50-2

Struts solves the most common problems of web development. By basing your application on the Struts framework, you can reuse proven solutions and focus on what’s unique to your own case. Struts is an open-source product distributed by the Apache Software Foundation. Struts in Action is a comprehensive introduction to the Struts framework. It covers initial design, data validation, database access, dynamic page assembly, localization, product configuration, and other important areas. It shows you how to use both JSP tags and Velocity templates. It carefully explains the Struts architecture and control flow, as well as how to extend framework classes.Differences between Struts 1.1 and Struts 1.0. are pointed out and a case-study illustrates the 1.0 to 1.1 transition. The book shows you dozens of proven design techniques, patterns, and strategies, many of them not found elsewhere.What’s Inside-Struts 1.1 and 1.0Jakarta Validator and Tile packagesJakarta Scaffold toolkitVelocity templatesHTTP, Java Servlets, and JSP tagsDynamic web programmingServlet-centric application designWorking with databases and data servicesDesign and development patternsTons of examples

Table of contents :
contents……Page 7
foreword……Page 19
preface……Page 23
acknowledgments……Page 26
about this book……Page 28
Introduction……Page 37
1.1.1 Who makes the Struts software?……Page 38
1.2 What are application frameworks?……Page 39
1.3 Enabling technologies……Page 40
1.3.1 Hypertext Transfer Protocol (HTTP)……Page 41
1.3.2 Common Gateway Interface (CGI)……Page 42
1.3.3 Java servlets……Page 43
1.3.4 JavaServer Pages……Page 44
1.3.5 JSP tags……Page 45
1.3.6 JavaBeans……Page 46
1.4 Struts from 30,000 feet……Page 48
1.4.2 Jump-starting development……Page 50
1.4.3 Where the rubber meets the road……Page 52
1.4.4 Looking back……Page 58
1.5 Summary……Page 62
Exploring the Struts architecture……Page 63
2.2.1 One step back, three steps forward……Page 64
2.2.3 Struts controller components……Page 65
2.2.4 Developing a web application with Struts……Page 70
2.3.1 The Web—a never-ending kluge……Page 71
2.3.2 The servlet solution……Page 72
2.3.3 Servlet frameworks……Page 73
2.3.4 The whitebox-blackbox continuum……Page 74
2.4.1 The evolution of MVC……Page 75
2.4.2 The rise of Model 2……Page 76
2.4.3 Application layers—decoupling the view……Page 77
2.4.4 How Struts implements Model 2, MVC, and layers……Page 78
2.5 Struts control flow……Page 80
2.5.1 The big picture……Page 81
2.5.2 The finer details……Page 82
2.5.3 Is Struts performant?……Page 86
2.6 The strengths and weaknesses of Struts……Page 87
2.6.1 The weak points……Page 88
2.6.2 Struts’ strong points……Page 90
2.7 Summary……Page 92
Building a simple application……Page 93
3.1 Strut by Strut……Page 94
3.2.1 Start here……Page 95
3.2.4 The logon screen……Page 96
3.2.6 The welcome screen, good-bye……Page 98
3.3.1 The browser source for the welcome screen……Page 99
3.3.2 The JSP source for the welcome screen……Page 100
3.3.3 The configuration source for the welcome screen……Page 103
3.3.4 The browser source for the logon screen……Page 104
3.3.6 The LogonSubmit source……Page 107
3.3.7 The LogonForm source……Page 108
3.3.8 The LogonAction source……Page 111
3.3.9 The LogoffAction source……Page 117
3.4.1 Defining the requirements……Page 120
3.4.2 Planning the application……Page 121
3.4.4 Setting up your development tools……Page 124
3.4.7 Setting up the struts-config.xml file……Page 126
3.4.8 Testing the deployment……Page 128
3.4.9 Constructing our welcome page……Page 129
3.4.10 Constructing the logon page……Page 130
3.4.11 Constructing the Constants class……Page 132
3.4.13 Creating the user directory……Page 133
3.4.14 Configuring the ActionErrors……Page 134
3.4.16 Amending the welcome page……Page 135
3.4.17 The Struts ActionForward Action……Page 136
3.5 Summary……Page 138
Configuring Struts components……Page 139
4.1.1 The rest of the family……Page 140
4.2.1 The web.xml file……Page 141
4.2.2 ActionServlet parameters……Page 144
4.3.1 Details, details……Page 147
4.3.3 The principle of Protected Variation……Page 149
4.4 The Struts configuration elements……Page 150
4.4.1 ……Page 152
4.4.2 ……Page 153
4.4.3 ……Page 154
4.4.4 ……Page 155
4.4.6 ……Page 157
4.4.7 ……Page 158
4.4.8 ……Page 159
4.4.9 Rolling your own……Page 160
4.4.10 A skeleton Struts config……Page 161
4.5 The application resources file……Page 162
4.6 The Ant build file……Page 164
4.7.1 Installing Java and a Java servlet container……Page 167
4.8 Configuring the Tiles framework……Page 168
4.9 Configuring the Struts Validator……Page 170
4.10 Getting started with the Struts Blank application……Page 171
4.11 Configuring modular applications……Page 173
4.11.1 Divide and conquer……Page 174
4.12 Sharing the Struts JAR……Page 176
4.13 Summary……Page 177
Coping with ActionForms……Page 181
5.1 Garbage in, treasure out……Page 182
5.1.1 ActionForm requirements……Page 184
5.2.1 The ActionForm as a field harvester……Page 185
5.2.2 The ActionForm as a data buffer……Page 187
5.2.3 The ActionForm as a data validator……Page 188
5.2.5 The ActionForm as a transfer object……Page 189
5.2.6 The ActionForm as a firewall……Page 190
5.3.1 ActionForms may share names……Page 191
5.3.4 ActionForms may nest other beans……Page 192
5.4.1 Map-backed ActionForms……Page 194
5.5 Why isn’t an ActionForm………Page 196
5.5.3 Why isn’t an ActionForm an interface?……Page 197
5.6 Debriefing ActionForms……Page 198
5.6.1 Implementing a business-layer interface……Page 200
5.6.2 Nesting a mutable value object……Page 201
5.6.3 Setting an immutable value object……Page 202
5.6.4 Setting a mutable value object……Page 203
5.6.5 Using a factory method……Page 204
5.6.6 Passing a Map……Page 205
5.6.7 Transferring values by reflection……Page 207
5.6.8 Using an adaptor class……Page 212
5.7 BaseForm……Page 213
5.7.2 Dispatch……Page 214
5.7.4 BaseMapForm……Page 215
5.8 Summary……Page 216
Wiring with ActionForwards……Page 217
6.1 What ActionForwards do……Page 218
6.2.1 Forward versus redirect……Page 219
6.3 Global and local forwards……Page 221
6.4.2 Adding parameters in the Action class……Page 222
6.5 Dynamic forwards……Page 223
6.7 Rolling your own ActionForward……Page 224
6.8 Summary……Page 225
Designing with ActionMappings……Page 227
7.1 Enter ActionMappings……Page 228
7.1.2 The ActionMappings catalog……Page 229
7.2 ActionMapping properties……Page 230
7.2.1 The path property……Page 231
7.2.3 The include property……Page 232
7.2.8 The scope property……Page 233
7.2.10 The input property……Page 234
7.2.11 The parameterproperty……Page 235
7.2.13 The prefix and suffix properties……Page 236
7.3.1 Local forwards……Page 237
7.4 Rolling your own ActionMapping……Page 238
7.5 Summary……Page 239
Working with Action objects……Page 241
8.2 Getting it done with Action objects……Page 242
8.2.1 What are Actions?……Page 243
8.2.2 When are Actions called?……Page 244
8.2.3 What do Actions do?……Page 245
8.2.4 What does an Action look like?……Page 251
8.3.1 Standard bridge Action classes……Page 253
8.3.2 Standard base Actions……Page 256
8.4 Chaining Actions……Page 262
8.5 Scaffold Actions……Page 263
8.5.1 Forward-only Actions……Page 264
8.5.2 Helper Actions……Page 270
8.6 Base View Actions……Page 273
8.7 Helper Action techniques……Page 274
8.7.1 Optional forwarding……Page 275
8.7.2 Calling ahead……Page 276
8.7.3 Catching chained exceptions……Page 277
8.7.4 Smart error forwarding……Page 279
8.7.5 Confirming success……Page 280
8.7.7 Reflecting methods……Page 281
8.7.8 Reflecting classes……Page 282
8.8 Using smart forwarding……Page 283
8.9 Summary……Page 288
Extending ActionServlet……Page 289
9.1 Where’s the beef?……Page 290
9.1.1 The servlet’s Gang of Three……Page 292
9.2 The RequestProcessor……Page 293
9.2.2 processRoles……Page 294
9.3 The ExceptionHandler……Page 296
9.4 PlugIn……Page 297
9.5 Summary……Page 298
Displaying dynamic content……Page 301
10.1.1 JSP tags—what are they good for?……Page 302
10.1.2 Struts and JSTL……Page 305
10.1.3 Struts tags and MVC……Page 307
10.2.1 How are tag extensions written?……Page 308
10.2.2 How are tag extensions installed?……Page 310
10.2.3 What tag extensions are not……Page 312
10.3 The Struts taglibs……Page 313
10.3.1 Features common to Struts tags……Page 314
10.3.2 The bean tags……Page 316
10.3.3 The html tags……Page 319
10.3.4 The logic tags……Page 321
10.4 Using Struts JSP tags……Page 324
10.4.2 Fundamentals……Page 325
10.4.3 Techniques……Page 334
10.4.4 Successful controls……Page 348
10.5.2 Servlet contexts……Page 349
10.6 Summary……Page 351
Developing applications with Tiles……Page 353
11.1.1 Layering with dynamic templates……Page 354
11.1.2 Template consequences……Page 355
11.1.3 Using templates……Page 356
11.1.4 Combining templates, Tiles, and Struts……Page 357
11.2 Building a layout template……Page 358
11.2.1 But what is a tile?……Page 360
11.2.2 Deploying a Tiles template……Page 362
11.2.3 Adding a style sheet……Page 363
11.2.4 Templates and MVC……Page 364
11.3.1 Declaring Definitions……Page 365
11.3.2 JSP declarations……Page 366
11.3.3 Configuration file declarations……Page 369
11.3.4 Using Definitions as ActionForwards……Page 372
11.4 Tile attributes……Page 373
11.4.2 importAttribute……Page 374
11.4.3 put……Page 375
11.5 Migrating an application to Tiles……Page 377
11.5.2 Testing the default configuration……Page 378
11.5.3 Reviewing the pages……Page 379
11.5.4 Refactoring a page with ……Page 382
11.5.5 Extracting the tags into a Definition……Page 389
11.5.6 Normalizing your base layout……Page 393
11.5.7 Refining your Definitions into base and extended classes……Page 394
11.5.8 Developing a routine……Page 395
11.5.9 Managing the migration……Page 396
11.6 Summary……Page 397
Validating user input……Page 399
12.1.1 Input we can’t refuse……Page 400
12.1.2 Web-tier validations……Page 401
12.1.3 Validator consequences……Page 402
12.2 Overview of the Struts Validator……Page 405
12.2.1 Logon example……Page 408
12.3 Basic validators……Page 413
12.3.2 The mask validator……Page 414
12.3.3 The range validator……Page 415
12.3.4 The maxLength validator……Page 416
12.3.7 The date validator……Page 417
12.4 Resource bundles……Page 418
12.4.2 Default validator messages……Page 419
12.4.3 Custom validator messages……Page 420
12.5 Configuration files……Page 421
12.6 Validator JSP tags……Page 422
12.7 ValidatorForm and ValidatorActionForm……Page 425
12.9.1 Creating pluggable validators……Page 426
12.10 Techniques……Page 428
12.10.2 Cancel buttons……Page 429
12.10.3 Custom messages……Page 430
12.10.4 Interrelated fields……Page 431
12.10.5 Combining validators with the validate method……Page 432
12.11.2 Testing the default configuration……Page 433
12.11.3 Reviewing your validations……Page 434
12.11.5 Selecting a validation to migrate……Page 435
12.11.7 Adding new entries to the ApplicationResources……Page 437
12.11.8 Calling the Struts Validator……Page 438
12.11.9 Test and repeat……Page 439
12.11.10 Removing the ActionForm subclass……Page 440
12.12 Summary……Page 442
Localizing content……Page 443
13.1 By any other name……Page 444
13.1.1 Why localize?……Page 445
13.1.2 How Java internationalization works……Page 446
13.2.1 Session Locale attribute……Page 451
13.2.2 MessageResources……Page 452
13.2.3 The default resource bundle……Page 453
13.2.5 ActionMessages……Page 455
13.2.6 Locale-sensitive JSP tags……Page 456
13.3 Localizing a Struts application……Page 461
13.3.1 Enabling localization……Page 462
13.3.2 Using the framework Locale object……Page 464
13.3.6 Using with other components……Page 465
13.4.1 Localizing the Struts Validator……Page 466
13.4.3 Localizing collections……Page 467
13.5 Summary……Page 469
Using data services with Struts……Page 471
14.1.1 JDBC from a patterns perspective……Page 472
14.2.1 Struts—bringing your own Model……Page 474
14.2.2 Defining business objects……Page 475
14.2.3 Designing business objects……Page 476
14.2.5 Mixing business with Actions (not)……Page 477
14.2.6 A simple example……Page 478
14.3 Using ProcessBeans and JDBC with Struts……Page 479
14.3.1 Introducing ProcessBeans……Page 480
14.3.2 ProcessBeans as transfer objects……Page 481
14.3.4 Executing ProcessBeans……Page 482
14.3.5 Accessing data services……Page 483
14.3.7 Coding a business activity……Page 485
14.3.8 ProcessBeans as a persistence layer……Page 488
14.4.1 ResultList methods……Page 489
14.5 Using helper Actions……Page 491
14.6 Using Lucene……Page 492
14.6.1 searchProperties redux……Page 493
14.7.1 Digesting RSS……Page 498
14.7.2 Retrieve and render……Page 499
14.7.3 Syndicating RSS……Page 500
14.8 Using EJBs with Struts……Page 502
14.8.1 Session Facade……Page 503
14.8.3 Implementation patterns……Page 504
14.9 Summary……Page 505
Artimus: pulling out the stops……Page 509
15.2 Scaffold—birth of a toolset……Page 510
15.3 About Artimus……Page 511
15.3.1 Building Artimus……Page 513
15.4 The deployment descriptor (web.xml)……Page 514
15.4.3 Our connection adaptor……Page 516
15.4.7 The URLs we protect……Page 517
15.5 ArtimusServlet……Page 518
15.5.3 Our extension point……Page 520
15.6 The application and SQL Properties files……Page 521
15.7 index.jsp……Page 522
15.8 Global forwards……Page 523
15.9 /find/Recent……Page 526
15.9.1 extends bean……Page 528
15.9.4 Access.findByLast and ResultList……Page 529
15.9.5 ProcessResult……Page 531
15.9.6 ProcessAction……Page 532
15.10 tiles.xml and Article.jsp……Page 533
15.10.2 baseStyle……Page 535
15.10.4 Tiles……Page 536
15.11 result.jsp……Page 538
15.11.3 RESULT……Page 540
15.12 Article actions……Page 544
15.13 view.jsp……Page 547
15.13.2 content……Page 548
15.13.3 contributor……Page 549
15.14 edit.jsp……Page 550
15.14.1 Article content……Page 552
15.14.4 Validation……Page 553
15.15 /do/Menu……Page 555
15.15.2 menu……Page 557
15.15.5 Our results……Page 559
15.16 menu.jsp……Page 560
15.16.2 /menu/Find……Page 562
15.16.3 /find/Last……Page 563
15.16.4 /menu/Contributor……Page 564
15.16.5 /menu/Manager……Page 565
15.17 Summary……Page 566
Redux: migrating to Struts 1.1……Page 567
16.1 Next station, Struts 1.1……Page 568
16.1.1 Struts 1.1 feature roundup……Page 569
16.2 Baseline changes……Page 572
16.2.1 Tiles in Struts 1.1……Page 574
16.2.2 Validator in Struts 1.1……Page 577
16.2.4 Other baseline changes to web.xml and struts-config.xml……Page 578
16.2.5 message.jsp (1.1)……Page 579
16.2.6 form.jsp (1.1)……Page 580
16.2.7 MenuCreate (1.1)……Page 581
16.3 Discretionary changes……Page 582
16.3.1 Form to DynaActionForm……Page 583
16.3.2 Action-based security……Page 584
16.3.4 Application resources in Struts 1.1……Page 587
16.4 Summary……Page 588
Velocity: replacing JSPs……Page 589
17.2 Change makes the framework……Page 590
17.3.3 Velocity is simple but powerful……Page 591
17.4 Using Velocity with web applications……Page 592
17.4.1 Using Velocity with servlet resources……Page 593
17.4.2 Using Velocity with context attributes……Page 594
17.4.3 How Velocity works with Struts……Page 595
17.4.4 The VelocityStruts toolkit……Page 596
17.5 Our logon templates……Page 597
17.6.1 Installing the VelocityViewServlet……Page 600
17.6.2 Deploying the Velocity servlet……Page 601
17.6.3 The toolbox configuration file……Page 602
17.7 Setting up struts-config……Page 603
17.8 Summary……Page 604
Design patterns……Page 607
A.1 A brief history of design patterns……Page 608
A.1.2 J2EE Blueprints……Page 609
A.2 Why patterns are important……Page 610
A.4 Struts—a Who’s Who of design patterns……Page 611
A.4.1 The Service to Worker pattern……Page 612
A.4.4 Value Object / Value Object Assembler patterns……Page 613
A.4.6 The Synchronizer Token pattern……Page 614
A.4.7 The Decorator pattern……Page 615
The struts-config API……Page 617
B.1 ……Page 618
B.1.3 ……Page 619
B.1.5 ……Page 620
B.1.6 ……Page 621
B.1.7 ……Page 622
B.1.8 ……Page 623
B.1.10 ……Page 624
B.1.11 ……Page 625
B.1.12 ……Page 626
B.1.13 ……Page 628
B.1.14 ……Page 630
B.1.15 ……Page 631
Taglib quick reference……Page 633
glossary……Page 639
references……Page 648
index……Page 658

Reviews

There are no reviews yet.

Be the first to review “Struts in Action: Building Web Applications with the Leading Java Framework”
Shopping Cart
Scroll to Top