You are previewing Struts 2 Design and Programming: A Tutorial.
O'Reilly logo
Struts 2 Design and Programming: A Tutorial

Book Description

Offering both theoretical explanations and real-world applications, this in-depth guide covers the 2.0 version of Struts, revealing how to design, build, and improve Java-based Web applications within the Struts development framework. Feature functionality is explained in detail to help programmers choose the most appropriate feature to accomplish their objectives, while other chapters are devoted to file uploading, paging, and object caching.

Table of Contents

  1. Copyright
  2. Introduction
    1. Why Servlets Are Not Dead
    2. The Problems with Model 1
    3. Model 2
    4. Struts Overview
    5. Upgrading to Struts 2
    6. Overview of the Chapters
    7. Prerequisites and Software Download
    8. Sample Applications
  3. 1. Model 2 Applications
    1. Model 2 Overview
    2. Model 2 with A Servlet Controller
      1. The Product Action Class
      2. The ControllerServlet Class
      3. The Views
      4. The Deployment Descriptor
      5. Using the Application
    3. Model 2 with A Filter Dispatcher
    4. Summary
  4. 2. Starting with Struts
    1. The Benefits of Struts
    2. How Struts Works
    3. Interceptors
    4. Struts Configuration Files
      1. The struts.xml File
        1. The package Element
        2. The include Element
        3. The action Element
        4. The result Element
        5. The global-results Element
        6. The Interceptor-related Elements
        7. The param Element
        8. The constant Element
      2. The struts.properties File
    5. A Simple Struts Application
      1. The Deployment Descriptor and the Struts Configuration File
      2. The Action Class
      3. Running the Application
    6. Dependency Injection
      1. Overview
      2. Forms of Dependency Injection
    7. Summary
  5. 3. Actions and Results
    1. Action Classes
    2. Accessing Resources
      1. The ServletActionContext Object
      2. Aware Interfaces
        1. ServletContextAware
        2. ServletRequestAware
        3. ServletResponseAware
        4. SessionAware
      3. Using Aware Interfaces to Access Resources
    3. Passing Static Parameters to An Action
    4. The ActionSupport Class
    5. Results
      1. Chain
      2. Dispatcher
      3. FreeMarker
      4. HttpHeader
      5. Redirect
      6. Redirect Action
      7. Stream
      8. Velocity
      9. XSLT
      10. PlainText
    6. Exception Handling with Exception Mapping
    7. Wildcard Mapping
    8. Dynamic Method Invocation
    9. Testing Action Classes
    10. Summary
  6. 4. OGNL
    1. The Value Stack
    2. Reading Object Stack Object Properties
    3. Reading Context Map Object Properties
    4. Invoking Fields and Methods
    5. Working with Arrays
    6. Working with Lists
    7. Working with Maps
    8. JSP EL: When OGNL Can’t Help
    9. Summary
  7. 5. Form Tags
    1. Using Struts Tags
    2. Common Attributes
    3. The form Tag
    4. The textfield, password, hidden Tags
    5. The submit Tag
    6. The reset Tag
    7. The label Tag
    8. The head Tag
    9. The textarea Tag
    10. The checkbox Tag
    11. The list, listKey, and listValue attributes
      1. Assigning A String
      2. Assigning a Map
      3. Assigning A Collection or An Object Array
    12. The radio Tag
    13. The select Tag
    14. Select Option Grouping with optgroup
    15. The checkboxlist Tag
    16. The combobox Tag
    17. The updownselect Tag
    18. The optiontransferselect Tag
    19. The doubleselect Tag
    20. Themes
    21. Summary
  8. 6. Generic Tags
    1. The property Tag
    2. The a Tag
    3. The action Tag
    4. The param Tag
    5. The bean Tag
    6. The date Tag
    7. The include Tag
    8. The set Tag
    9. The push Tag
    10. The url Tag
    11. The if, else, and elseIf Tags
    12. The iterator Tag
    13. The append Tag
    14. The merge Tag
    15. The generator Tag
    16. The sort Tag
    17. The subset Tag
    18. Summary
  9. 7. Type Conversion
    1. Type Conversion Overview
    2. Customizing Conversion Error Messages
    3. Custom Type Converters
      1. Configuring Custom Converters
      2. Custom Converter Examples
    4. Extending StrutsTypeConverter
    5. Working with Complex Objects
    6. Working with Collections
    7. Working with Maps
    8. Summary
  10. 8. Input Validation
    1. Validator Overview
    2. Validator Configuration
    3. Bundled Validators
      1. required Validator
      2. requiredstring validator
      3. stringlength Validator
      4. int Validator
      5. date Validator
      6. email Validator
      7. url Validator
      8. regex Validator
      9. expression and fieldexpression Validators
        1. The expression Validator Example
        2. The fieldexpression Validator Example
      10. conversion Validator
      11. visitor Validator
        1. Validating a Complext Object (app08b)
        2. Using the visitor Validator (app08c)
        3. Using the visitor Validator in different contexts (app08d)
    4. Writing Custom Validators
      1. Registration
      2. Example
    5. Programmatic Validation Using Validateable
    6. Summary
  11. 9. Message Handling and Internationalization
    1. Locales and Java Resource Bundles
    2. Internationalization Support in Struts
    3. The text Tag
    4. The i18n Tag
    5. Manually Selecting A Resource Bundle
    6. Summary
  12. 10. Model Driven and Prepare Interceptors
    1. Separating the Action and the Model
    2. The Model Driven Interceptor
    3. The Preparable Interceptor
    4. Summary
  13. 11. The Persistence Layer
    1. The Data Access Object Pattern
      1. The Simplest Implementation of the DAO Pattern
      2. The DAO Pattern with A DAO Interface
      3. The DAO Pattern with the Abstract Factory Pattern
    2. Implementing the DAO Pattern
      1. The DAO Interface and the DAOBase Class
      2. The EmployeeDAO Interface
      3. The EmployeeDAOMySQLImpl Class
      4. The DAOFactory Class
      5. The EmployeeManager Class
      6. Running the Application
    3. Hibernate
    4. Summary
  14. 12. File Upload
    1. File Upload Overview
    2. File Upload in Struts
    3. The File Upload Interceptor
    4. Single File Upload Example
    5. Multiple File Upload Example
    6. Summary
  15. 13. File Download
    1. File Download Overview
    2. The Stream Result Type
    3. Programmatic File Download
    4. Summary
  16. 14. Securing Struts Applications
    1. Principals and Roles
    2. Writing Security Policies
      1. Protecting Resources
      2. Specifying the Login Method
    3. Authentication Methods
      1. Using Basic Authentication
      2. Using Form-Based Authentication
    4. Hiding Resources
    5. Struts Security Configuration
    6. Programmatic Security
      1. The getAuthType Method
      2. The isUserInRole Method
      3. The getUserPrincipal Method
      4. The getRemoteUser Method
    7. Summary
  17. 15. Preventing Double Submits
    1. Managing Tokens
    2. Using the Token Interceptor
    3. Using the Token Session Interceptor
    4. Summary
  18. 16. Debugging and Profiling
    1. The debug Tag
    2. The Debugging Interceptor
    3. Profiling
    4. Summary
  19. 17. Progress Meters
    1. The Execute and Wait Interceptor
    2. Using the Execute and Wait Interceptor
    3. Using A Custom Wait Page
    4. Summary
  20. 18. Custom Interceptors
    1. The Interceptor Interface
    2. Writing A Custom Interceptor
    3. Using DataSourceInjectorInterceptor
    4. Summary
  21. 19. Custom Result Types
    1. Overview
    2. Writing A Custom Plugin
    3. Using the New Result Type
    4. Summary
  22. 20. Velocity
    1. Overview
    2. Velocity Implicit Objects
    3. Tags
    4. Velocity Example
    5. Summary
  23. 21. FreeMarker
    1. Overview
    2. FreeMarker Tags
    3. Example
    4. Summary
  24. 22. XSLT Results
    1. Overview
    2. The XSLT Result Type
    3. Example
    4. Summary
  25. 23. Plug-ins
    1. Overview
    2. The Plug-in Registry
    3. Writing A Custom Plugin
    4. Using the Captcha Plug-in
    5. Summary
  26. 24. The Tiles Plug-in
    1. The Problem with JSP Includes
    2. Tiles Layout and Definition
      1. The Layout Page
      2. Tiles Definitions
    3. Struts Tiles Plugin
    4. Struts Tiles Example
    5. Summary
  27. 25. JFreeChart Plug-ins
    1. The JFreeChart API
      1. The JFreeChart Class
      2. Plot
    2. Using the Standard Plugin
    3. Using the BrainySoftware JFreeChart Plugin
    4. Summary
  28. 26. Zero Configuration
    1. Conventions
    2. Annotations
      1. @Result
      2. @Results
      3. @Namespace
      4. @ParentPackage
    3. The CodeBehind Plug-in
    4. Summary
  29. 27. AJAX
    1. AJAX Overview
    2. Dojo’s Event System
    3. Using the Struts Dojo Plug-in
    4. The head Tag
    5. The div Tag
      1. Example 1
      2. Example 2
      3. Example 3
    6. The a Tag
    7. The submit Tag
    8. The bind Tag
    9. The datetimepicker Tag
    10. The tabbedpanel Tag
    11. The textarea Tag
    12. The autocompleter Tag
      1. Example 1
      2. Example 2
      3. Example 3
    13. The tree and treenode Tags
      1. Example 1
      2. Example 2
    14. Summary
  30. A. Struts Configuration
    1. The struts.xml File
      1. The action Element
      2. The bean Element
      3. The constant Element
      4. The default-action-ref Element
      5. The default-interceptor-ref Element
      6. The exception-mapping Element
      7. The global-exception-mappings Element
      8. The global-results Element
      9. The include Element
      10. The interceptor Element
      11. The interceptor-ref Element
      12. The interceptor-stack Element
      13. The interceptors Element
      14. The package Element
      15. The param Element
      16. The result Element
      17. The result-type Element
      18. The result-types Element
      19. The struts-default.xml File
    2. The struts.properties File
  31. B. The JSP Expression Language
    1. The Expression Language Syntax
      1. Reserved Words
      2. The [ ] and . Operators
      3. The Evaluation Rule
    2. Accessing JavaBeans
    3. EL Implicit Objects
      1. pageContext
      2. initParam
      3. param
      4. paramValues
      5. header
      6. headerValues
      7. cookie
      8. applicationScope, sessionScope, requestScope, and pageScope
    4. Using Other EL Operators
      1. Arithmetic Operators
      2. Relational Operators
      3. Logical Operators
      4. The Conditional Operator
      5. The empty Operator
    5. Configuring the EL in JSP 2.0 and Later Versions
      1. Achieving Script-Free JSPs
      2. Deactivating the EL Evaluation
    6. Summary
  32. C. Annotations
    1. An Overview of Annotations
      1. Annotations and Annotation Types
      2. Annotation Syntax
      3. The Annotation Interface
    2. Standard Annotations
      1. Override
      2. Deprecated
      3. SuppressWarnings
    3. Standard Meta-Annotations
      1. Documented
      2. Inherited
      3. Retention
      4. Target
    4. Custom Annotation Types
      1. A Custom Annotation Type
    5. Using the Custom Annotation Type
      1. Using Reflection to Query Annotations