Struts
Struts 2 in Action
DONALD BROWN CHAD MICHAEL DAVIS SCOTT STANLICK
MANNING
Greenwich (74° w. long.)
For online information and ordering of this and other Manning books, please visit 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. SoundView Court 3B fax: (609) 877-8256 Greenwich, CT 06830 email: orders@manning.com
©2008 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 bymanufacturers 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 we publish printed on acid-free paper, and weexert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15% recycled and processed without the use of elemental chlorine.
Manning Publications Co. Sound View Court 3B Greenwich, CT 06830
Copyeditor: Benjamin Berg Typesetter: Gordan Salinovic Cover designer: Leslie Haimes
ISBN1-933988-07-X Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 13 12 11 10 09 08
To world peace and a global redistribution of prosperity
brief contents
PART 1 STRUTS 2: A BRAND NEW FRAMEWORK ..................................1
1 2
■ ■
Struts 2: the modern web application framework Saying hello to Struts 2 20
3
PART 2
CORE CONCEPTS: ACTIONS, INTERCEPTORS, ANDTYPE CONVERSION ...................................................41
3 4 5
■ ■ ■
Working with Struts 2 actions
43 74 101
Adding workflow with interceptors
Data transfer: OGNL and type conversion
PART 3
BUILDING THE VIEW: TAGS AND RESULTS ...........................129
6 7 8
■ ■ ■
Building a view: tags UI component tags Results in detail 202
131 167
vii
PART 4IMPROVING YOUR APPLICATION .......................................229
9 10 11
■ ■ ■
Integrating with Spring and Hibernate/JPA Exploring the validation framework Understanding internationalization 255 282
231
PART 5
ADVANCED TOPICS AND BEST PRACTICES ............................307
12 13 14 15
■ ■ ■ ■
Extending Struts 2 with plug-ins Best practices 326 360
309
Migration fromStruts Classic 339 Advanced topics
contents
preface xvii acknowledgments xix about this book xxii about the title xxvii about the cover illustration xxviii
PART 1 STRUTS 2: A BRAND NEW FRAMEWORK ......................1
1
Struts 2: the modern web application framework 3
1.1 Web applications: a quick study
■
4
■
Using the Web to build applications 4 Examining the technologystack 4 Surveying the domain 8
1.2 1.3
Frameworks for web applications
What’s a framework? 10
■
9
10
Why use a framework?
The Struts 2 framework 11
A brief history 11 Struts 2 from 30,000 feet: the MVC pattern 12 How Struts 2 works 15
■ ■
1.4
Summary
18
ix
x
CONTENTS
2
Saying hello to Struts 2 20
2.1 Declarative architecture 21
Two kinds ofconfiguration 21 Two mechanisms for declaring your architecture 22 Intelligent defaults 25
■ ■
2.2
A quick hello
25
■
Deploying the sample application 26 application 30
Exploring the HelloWorld
2.3 2.4
HelloWorld using annotations Summary 38
36
PART 2 CORE CONCEPTS: ACTIONS, INTERCEPTORS, AND TYPE CONVERSION .......................................41
3
Working with Struts...
Regístrate para leer el documento completo.