Introduction


Actions control the flow of data and navigation in a Struts application. Each Action acts like a decision point in a flow chart. It's the place where you can decide what data to create, what data to save, and where to send users based on their input. A Struts application doesn't require that every request be routed through an Action, but doing so gives you a level of control that will allow your application to adapt as requirements and new features are changed and added.

Do you feel like your application is exploding with hundreds of custom Actions? If it is, you aren't alone. This condition can be acceptable, but you may not be leveraging Struts Actions to their full extent. Using the recipes in this chapter will enable you to get more reuse from your Actions and reduce the number of custom classes that you have to maintain.

A number of the recipes in this chapter utilize Action subclasses included with Struts. These pre-built actions are found in the org.apache.struts.actions package. Some of these actions are designed to be extended, and others are used as is. The DispatchAction and its provided subclasses, LookupDispatchAction and MappingDispatchAction, fall into this first category. These actions reduce the amount of code you have to write by replacing multiple related Actions with a single Action that supports multiple operations.

You use two other pre-built actions, ForwardAction and IncludeAction, directlyno subclassing required. These actions perform the same functions as the javax.servlet.RequestDispatcher provided by the Java Servlet API. The ForwardAction forwards an HTTP request to another resource such as a servlet, JSP, or static HTML page. The IncludeAction includes content from another resource, such as a servlet or JSP, which generates a partial HTTP response.

Struts provides a SwitchAction used to change the current Struts module and a LocaleAction used to change the current locale. This chapter covers the SwitchAction (however, the LocaleAction is discussed in Recipe 12.4) and some programming techniques and guidelines specifically related to working with Actions.



    Jakarta Struts Cookbook
    Jakarta Struts Cookbook
    ISBN: 059600771X
    EAN: 2147483647
    Year: 2005
    Pages: 200

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net