You are previewing Jakarta Struts Cookbook.
O'Reilly logo
Jakarta Struts Cookbook

Book Description

The Jakarta Struts Framework is a popular open source platform for building web applications from top to bottom with Java. While this popularity has led to a wealth of online and in-print documentation, developers still find themselves faced with a number of common tasks that are not clearly and succinctly explained. In these situations, programmers can now turn to the Jakarta Struts Cookbook an amazing collection of code solutions to common--and uncommon--problems encountered when working with the Struts Framework. Among many other recipes, this book explains how to:

  • display data in complex HTML tables

  • use JSP, the JSTL, and JavaScript in your user interface

  • define static and dynamic action forms

  • validate data and respond to errors

  • use Logging, Validation, and Exception Handling

  • integrate Struts with persistence frameworks like Hibernate and iBATIS

This look-up reference is just what today's time-pressed developers need. With solutions to real-world problems just a few page flips away, information is instantly available. And while the book's solutions focus on getting to the point, each recipe's discussion section imparts valuable concept and insight from a Struts veteran. The Jakarta Struts Cookbook is perfect for independent developers, large development teams, and everyone in between who wishes to use the Struts Framework to its fullest potential. Plus, it s completely up-to-date with the latest versions of Framework, so readers can be sure the information is viable.

Table of Contents

  1. Jakarta Struts Cookbook
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Preface
      1. Audience
      2. Scope and Organization
      3. Assumptions This Book Makes
      4. Conventions Used in This Book
        1. Programming Conventions
        2. Typographical Conventions
      5. Using Code Examples
      6. Comments and Questions
      7. Safari Enabled
      8. Acknowledgments
    4. 1. Getting Started: Enabling Struts Development
      1. Introduction
      2. 1.1. Downloading Struts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 1.2. Deploying the Struts Example Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 1.3. Migrating from Struts 1.0 to Struts 1.1
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 1.4. Upgrading from Struts 1.1 to Struts 1.2
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 1.5. Converting JSP Applications to Struts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 1.6. Managing Struts Configuration Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 1.7. Using Ant to Build and Deploy
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 1.8. Generating Struts Configuration Files Using XDoclet
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    5. 2. Configuring Struts Applications
      1. Introduction
      2. 2.1. Using Plug-ins for Application Initialization
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 2.2. Eliminating Tag Library Declarations
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 2.3. Using Constants on JSPs
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 2.4. Using Multiple Struts Configuration Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 2.5. Factoring Your Application into Modules
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 2.6. Using Multiple Resource Bundles
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 2.7. Accessing Message Resources from a Database
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 2.8. Selectively Disabling Actions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    6. 3. User Interface
      1. Introduction
      2. 3.1. Using JSTL
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 3.2. Using the Struts-EL Tags
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 3.3. Displaying Indexed Properties
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 3.4. Using Indexed Properties on Forms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 3.5. Using Indexed Properties in a JSTL Loop
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 3.6. Submitting a Form from an Image
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 3.7. Generating JavaScript on the Fly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 3.8. Dynamically Changing Select Options Using JavaScript
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 3.9. Generating Dynamic Select List Options
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 3.10. Filtering Text Input
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 3.11. Generating a Set of Related Radio Buttons
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 3.12. Handling Unchecked Checkboxes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 3.13. Handling Date Input Fields
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 3.14. Setting Tab Order
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 3.15. Generating URLs
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 3.16. Adding Request Parameters to a Link
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 3.17. Using Frames
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 3.18. Defeating Browser Caching
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    7. 4. Tables, Sorting, and Grouping
      1. Introduction
      2. 4.1. Creating a Horizontal Bar Chart
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 4.2. Creating a Vertical Bar Chart
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 4.3. Alternating Table Row Colors
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 4.4. Sorting HTML Tables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 4.5. Paging Tables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 4.6. Using the Display Tag Library
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    8. 5. Processing Forms
      1. Introduction
      2. 5.1. Creating Dynamic Action Forms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 5.2. Setting DynaActionForm Initial Values
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 5.3. Using a List-Backed Form Property
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 5.4. Using a Map-Backed Form Property
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 5.5. Lazy Dynamic Action Forms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 5.6. Populating Value Objects from ActionForms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 5.7. Automatically Creating ActionForms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    9. 6. Leveraging Actions
      1. Introduction
      2. 6.1. Creating a Base Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 6.2. Relaying Actions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 6.3. Returning the HTTP Response
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 6.4. Writing Thread-Safe Actions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 6.5. Forwarding Requests
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 6.6. Including the Response from a Servlet or JSP
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 6.7. Changing the Current Module
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 6.8. Managing Related Operations from a Central Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 6.9. Submitting a Form from Localized Form Controls
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 6.10. Dispatching to Related Operations with Action Mappings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    10. 7. Execution Control
      1. Introduction
      2. 7.1. Performing Tasks at Application Startup
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 7.2. Tracking Client Sessions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 7.3. Monitoring User Logins
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 7.4. Forwarding Users to Alternate Destinations
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 7.5. Forwarding Users to a Module
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 7.6. Creating a Wizard-Style Page Flow
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 7.7. Determining the Action Based on User Input
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 7.8. Using Wildcards in Action Paths
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 7.9. Preventing Double Form Submissions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 7.10. Allowing Users to Upload Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 7.11. Displaying a File from the Server
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    11. 8. Input Validation
      1. Introduction
        1. Configuring the Validator
        2. See Also
      2. 8.1. Reusing Validator Attribute Values
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 8.2. Validating Using Regular Expressions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 8.3. Validating Dependent Fields in Struts 1.1
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 8.4. Validating Dependent Fields in Struts 1.2
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 8.5. Validating an Indexed Property
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 8.6. Validating Dates
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 8.7. Validating Field Equality with a Custom Validator
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 8.8. Validating Field Equality in Struts 1.2
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 8.9. Validating Two or More Choices
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 8.10. Adding a Custom Validation to a Validator Form
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 8.11. Validating a Wizard Form
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 8.12. Localizing Validation Rules
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    12. 9. Exception and Error Handling
      1. Introduction
      2. 9.1. Simplifying Exception Processing in an Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 9.2. Custom Processing for Declared Exceptions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 9.3. Using Exception Error Codes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 9.4. Using a Global Error Page
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 9.5. Reporting Errors and Messages from an Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 9.6. Formatting Error Messages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    13. 10. Connecting to the Data
      1. Introduction
      2. 10.1. Accessing JDBC Data Sources from an Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 10.2. Displaying Relational Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 10.3. Mapping SQL Data to Java Objects
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 10.4. Integrating Struts with Hibernate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 10.5. Decoupling Your Application from External Services
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 10.6. Integrating Spring with Struts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 10.7. Loading XML Data into Your Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 10.8. Refreshing Application Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    14. 11. Security
      1. Introduction
      2. 11.1. Securing Actions Using a Base Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 11.2. Checking for User Login on Any Struts Reques t
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 11.3. Securing a JSP Page
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 11.4. Restricting Actions by Role
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 11.5. Implementing "Remember Me" Logins
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 11.6. Ensuring Security Across Your Entire Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 11.7. Allowing a User to Log in Automatically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 11.8. Limiting Access for Specific URLs by Role
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 11.9. Letting the Container Manage Security
        1. Problem
        2. Solution
        3. Discussion
          1. 11.9.3.1. Authentication and authorization
          2. 11.9.3.2. Secure transport
        4. See Also
      11. 11.10. Mixing Application-Managed and Container-Managed Security
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 11.11. Configuring Actions to Require SSL
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 11.12. Limiting the Size of Uploaded Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    15. 12. Internationalization
      1. Introduction
      2. 12.1. Detecting Browser Language Settings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 12.2. Sharing Message Resources with JSTL
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 12.3. Using an Application-Wide Locale
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 12.4. Changing Locale on the Fly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 12.5. Creating Localized Messages from an Action
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 12.6. Displaying Locale-Specific Text
        1. Problem
        2. Solution
        3. Discussion
          1. 12.6.3.1. Using the Struts bean tags
          2. 12.6.3.2. Using the JSTL format tags
        4. See Also
      8. 12.7. Displaying Locale-Specific Images
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 12.8. Supporting Character Sets
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 12.9. Localizing Look and Feel
        1. Problem
        2. Solution
          1. 12.9.2.1. Using Struts tags
          2. 12.9.2.2. Using JSTL tags
        3. Discussion
        4. See Also
    16. 13. Testing and Debugging
      1. Introduction
      2. 13.1. Deploying an Application Automatically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 13.2. Configuring Struts Logging
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 13.3. Adding Logging to Your Own Classes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 13.4. Enabling Remote Debugging
        1. Problem
        2. Solution
          1. 13.4.2.1. JDK 1.3
          2. 13.4.2.2. JDK 1.4
        3. Discussion
        4. See Also
      6. 13.5. Troubleshooting JSP Pages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 13.6. Testing Your Actions with Mock Objects
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 13.7. Testing Your Actions in the Container
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 13.8. Testing Application Functionality
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    17. 14. Tiles and Other Presentation Approaches
      1. Introduction
      2. 14.1. Reusing a Common Page Layout with Tiles
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 14.2. Extending Tile Definitions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 14.3. Displaying Tiles Using a Struts Forward
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 14.4. Creating Tabbed Panes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 14.5. Using Tiles for I18N
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 14.6. Using Tiles in a Modular Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 14.7. Reusing a Common Page Layout with SiteMesh
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 14.8. Integrating JavaServer Faces with Struts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 14.9. Integrating Struts and Velocity
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 14.10. Integrating Struts and XSLT
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    18. About the Author
    19. Colophon
    20. SPECIAL OFFER: Upgrade this ebook with O’Reilly