Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts.action
Class Action

    java.lang.Object
      |
      +--org.apache.struts.action.Action

Direct Known Subclasses:
  ActionBase, AddFormBeanAction, AddForwardAction, AddMappingAction, DispatchAction, ForwardAction, IncludeAction, ReloadAction, RemoveFormBeanAction, RemoveForwardAction, RemoveMappingAction

public class Action
extends java.lang.Object

An Action is an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. The controller (ActionServlet) will select an appropriate Action for each request, create an instance (if necessary), and call the `perform` method.

Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. In this means you should design with the following items in mind:

- Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action.
- Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary.

When an `Action` instance is first created, the controller servlet will call `setServlet()` with a non-null argument to identify the controller servlet instance to which this Action is attached. When the controller servlet is to be shut down (or restarted), the `setServlet()` method will be called with a `null` argument, which can be used to clean up any allocated resources in use by this Action.

Version:
  $Revision: 1.1 $ $Date: 2001-09-17 21:13:30 +0100 (Mon, 17 Sep 2001) $
Author:
  Craig R. McClanahan

Field Summary
`static java.lang.String` | `DATA_SOURCE_KEY` The context attributes key under which our default configured data source (which must implement `javax.sql.DataSource`) is stored, if one is configured for this application.
`protected static java.util.Locale` | `defaultLocale` The system default Locale.
`static java.lang.String` | `ERROR_KEY` The request attributes key under which your action should store an `org.apache.struts.action.ActionErrors` object, if you are using the corresponding custom tag library elements.
`static java.lang.String` | `EXCEPTION_KEY` The request attributes key under which Struts custom tags might store a `Throwable` that caused them to report a JspException at runtime.
`static java.lang.String` | `FORM_BEANS_KEY` The context attributes key under which our `org.apache.struts.action.ActionFormBeans` collection is normally stored, unless overridden when initializing our ActionServlet.
`static java.lang.String` | `FORWARDS_KEY` The context attributes key under which our `org.apache.struts.action.ActionForwards` collection is normally stored, unless overridden when initializing our ActionServlet.
`static java.lang.String` | `LOCALE_KEY` The session attributes key under which the user's selected `java.util.Locale` is stored, if any.
`static java.lang.String` | `MAPPING_KEY` The request attributes key under which our `org.apache.struts.ActionMapping` instance is passed.
`static java.lang.String` | `MAPPINGS_KEY` The context attributes key under which our `org.apache.struts.action.ActionMappings` collection is normally stored, unless overridden when initializing our ActionServlet.
`static java.lang.String` | `MESSAGES_KEY` The context attributes key under which our application resources are normally stored, unless overridden when initializing our ActionServlet.
`static java.lang.String` | `MULTIPART_KEY` The request attributes key under which our multipart class is stored.
`protected ActionServlet` | `servlet` The controller servlet to which we are attached.
`static java.lang.String` | `SERVLET_KEY` The context attributes key under which we store the mapping defined for our controller serlet, which will be either a path-mapped pattern (`/action/*`) or an extension mapped pattern (`*.do`).
`static java.lang.String` | `TRANSACTION_TOKEN_KEY` The session attributes key under which our transaction token is stored, if it is used.

Constructor Summary
`Action()`

Method Summary
`protected java.lang.String` | `generateToken(javax.servlet.http.HttpServletRequest request)` Generate a new transaction token, to be used for enforcing a single request for a particular transaction.
`protected java.util.Locale` | `getLocale(javax.servlet.http.HttpServletRequest request)` Return the user's currently selected Locale.
`protected MessageResources` | `getResources()` Return the message resources for this application.
`ActionServlet` | `getServlet()` Return the controller servlet instance to which we are attached.
`protected boolean` | `isCancelled(javax.servlet.http.HttpServletRequest request)` Returns `true` if the current form's cancel button was pressed.
`protected boolean` | `isTokenValid(javax.servlet.http.HttpServletRequest request)` Return `true` if there is a transaction token stored in the user's current session, and the value submitted as a request parameter with this action matches it.
`ActionForward` | `perform(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it).
`ActionForward` | `perform(ActionMapping mapping, ActionForm form, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)` Process the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it).
`ActionForward` | `perform(ActionServlet servlet, ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Deprecated. Use the new perform() method without a servlet argument
`ActionForward` | `perform(ActionServlet servlet, ActionMapping mapping, ActionForm form, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)` Deprecated. Use the new perform() method without a servlet argument
`protected void` | `resetToken(javax.servlet.http.HttpServletRequest request)` Reset the saved transaction token in the user's session.
`protected void` | `saveErrors(javax.servlet.http.HttpServletRequest request, ActionErrors errors)` Save the specified error messages keys into the appropriate request attribute for use by the <struts:errors> tag, if any messages are required.
`protected void` | `saveToken(javax.servlet.http.HttpServletRequest request)` Save a new transaction token in the user's current session, creating a new session if necessary.
`protected void` | `setLocale(javax.servlet.http.HttpServletRequest request, java.util.Locale locale)` Set the user's currently selected Locale.
`void` | `setServlet(ActionServlet servlet)` Set the controller servlet instance to which we are attached (if `servlet` is non-null), or release any allocated resources (if `servlet` is null).
`protected java.lang.String` | `toHex(byte[] buffer)` Convert a byte array to a String of hexadecimal digits and return it.

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### DATA_SOURCE_KEY

    public static final java.lang.String DATA_SOURCE_KEY

  The context attributes key under which our default configured data source (which must implement `javax.sql.DataSource`) is stored, if one is configured for this application.

### ERROR_KEY

    public static final java.lang.String ERROR_KEY

  The request attributes key under which your action should store an `org.apache.struts.action.ActionErrors` object, if you are using the corresponding custom tag library elements.

### EXCEPTION_KEY

    public static final java.lang.String EXCEPTION_KEY

  The request attributes key under which Struts custom tags might store a `Throwable` that caused them to report a JspException at runtime. This value can be used on an error page to provide more detailed information about what really went wrong.

### FORM_BEANS_KEY

    public static final java.lang.String FORM_BEANS_KEY

  The context attributes key under which our `org.apache.struts.action.ActionFormBeans` collection is normally stored, unless overridden when initializing our ActionServlet.

### FORWARDS_KEY

    public static final java.lang.String FORWARDS_KEY

  The context attributes key under which our `org.apache.struts.action.ActionForwards` collection is normally stored, unless overridden when initializing our ActionServlet.

### LOCALE_KEY

    public static final java.lang.String LOCALE_KEY

  The session attributes key under which the user's selected `java.util.Locale` is stored, if any. If no such attribute is found, the system default locale will be used when retrieving internationalized messages. If used, this attribute is typically set during user login processing.

### MAPPING_KEY

    public static final java.lang.String MAPPING_KEY

  The request attributes key under which our `org.apache.struts.ActionMapping` instance is passed.

### MAPPINGS_KEY

    public static final java.lang.String MAPPINGS_KEY

  The context attributes key under which our `org.apache.struts.action.ActionMappings` collection is normally stored, unless overridden when initializing our ActionServlet.

### MESSAGES_KEY

    public static final java.lang.String MESSAGES_KEY

  The context attributes key under which our application resources are normally stored, unless overridden when initializing our ActionServlet.

### MULTIPART_KEY

    public static final java.lang.String MULTIPART_KEY

  The request attributes key under which our multipart class is stored.

### SERVLET_KEY

    public static final java.lang.String SERVLET_KEY

  The context attributes key under which we store the mapping defined for our controller serlet, which will be either a path-mapped pattern (`/action/*`) or an extension mapped pattern (`*.do`).

### TRANSACTION_TOKEN_KEY

    public static final java.lang.String TRANSACTION_TOKEN_KEY

  The session attributes key under which our transaction token is stored, if it is used.

### defaultLocale

    protected static java.util.Locale defaultLocale

  The system default Locale.

### servlet

    protected ActionServlet servlet

  The controller servlet to which we are attached.

Constructor Detail

### Action

    public Action()

Method Detail

### getServlet

    public ActionServlet getServlet()

  Return the controller servlet instance to which we are attached.

### setServlet

    public void setServlet(ActionServlet servlet)

  Set the controller servlet instance to which we are attached (if `servlet` is non-null), or release any allocated resources (if `servlet` is null).
  Parameters:
    `servlet` - The new controller servlet, if any

### perform

    public ActionForward perform(ActionServlet servlet,
                                 ActionMapping mapping,
                                 ActionForm form,
                                 javax.servlet.ServletRequest request,
                                 javax.servlet.ServletResponse response)
                          throws java.io.IOException,
                                 javax.servlet.ServletException

  Deprecated. Use the new perform() method without a servlet argument

  Process the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it). Return an `ActionForward` instance describing where and how control should be forwarded, or `null` if the response has already been completed.
  Parameters:
    `servlet` - The ActionServlet instance owning this Action
    `mapping` - The ActionMapping used to select this instance
    `actionForm` - The optional ActionForm bean for this request (if any)
    `request` - The servlet request we are processing
    `response` - The servlet response we are processing
  Throws:
    `java.io.IOException` - if an input/output error occurs
    `javax.servlet.ServletException` - if a servlet exception occurs

### perform

    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 javax.servlet.ServletRequest request,
                                 javax.servlet.ServletResponse response)
                          throws java.io.IOException,
                                 javax.servlet.ServletException

  Process the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it). Return an `ActionForward` instance describing where and how control should be forwarded, or `null` if the response has already been completed.

  The default implementation attempts to forward to the HTTP version of this method.

  Parameters:
    `mapping` - The ActionMapping used to select this instance
    `actionForm` - The optional ActionForm bean for this request (if any)
    `request` - The non-HTTP request we are processing
    `response` - The non-HTTP response we are creating
  Throws:
    `java.io.IOException` - if an input/output error occurs
    `javax.servlet.ServletException` - if a servlet exception occurs

### perform

    public ActionForward perform(ActionServlet servlet,
                                 ActionMapping mapping,
                                 ActionForm form,
                                 javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws java.io.IOException,
                                 javax.servlet.ServletException

  Deprecated. Use the new perform() method without a servlet argument

  Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return an `ActionForward` instance describing where and how control should be forwarded, or `null` if the response has already been completed.
  Parameters:
    `servlet` - The ActionServlet instance owning this Action
    `mapping` - The ActionMapping used to select this instance
    `actionForm` - The optional ActionForm bean for this request (if any)
    `request` - The servlet request we are processing
    `response` - The servlet response we are processing
  Throws:
    `java.io.IOException` - if an input/output error occurs
    `javax.servlet.ServletException` - if a servlet exception occurs

### perform

    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws java.io.IOException,
                                 javax.servlet.ServletException

  Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return an `ActionForward` instance describing where and how control should be forwarded, or `null` if the response has already been completed.
  Parameters:
    `mapping` - The ActionMapping used to select this instance
    `actionForm` - The optional ActionForm bean for this request (if any)
    `request` - The HTTP request we are processing
    `response` - The HTTP response we are creating
  Throws:
    `java.io.IOException` - if an input/output error occurs
    `javax.servlet.ServletException` - if a servlet exception occurs

### generateToken

    protected java.lang.String generateToken(javax.servlet.http.HttpServletRequest request)

  Generate a new transaction token, to be used for enforcing a single request for a particular transaction.
  Parameters:
    `request` - The request we are processing

### getLocale

    protected java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)

  Return the user's currently selected Locale.
  Parameters:
    `request` - The request we are processing

### getResources

    protected MessageResources getResources()

  Return the message resources for this application.

### isCancelled

    protected boolean isCancelled(javax.servlet.http.HttpServletRequest request)

  Returns `true` if the current form's cancel button was pressed. This method will check if the cancel button generated by CancelTag was pressed by the user in the current request. If true, validation performed by an ActionForm validate() method will have been skipped by the controller servlet.
  Parameters:
    `request` - The servlet request we are processing
  See Also:
    `CancelTag`, `ValidatingActionForm`

### isTokenValid

    protected boolean isTokenValid(javax.servlet.http.HttpServletRequest request)

  Return `true` if there is a transaction token stored in the user's current session, and the value submitted as a request parameter with this action matches it. Returns `false` under any of the following circumstances:
  - No session associated with this request
  - No transaction token saved in the session
  - No transaction token included as a request parameter
  - The included transaction token value does not match the transaction token in the user's session
  Parameters:
    `request` - The servlet request we are processing

### resetToken

    protected void resetToken(javax.servlet.http.HttpServletRequest request)

  Reset the saved transaction token in the user's session. This indicates that transactional token checking will not be needed on the next request that is submitted.
  Parameters:
    `request` - The servlet request we are processing

### saveErrors

    protected void saveErrors(javax.servlet.http.HttpServletRequest request,
                              ActionErrors errors)

  Save the specified error messages keys into the appropriate request attribute for use by the <struts:errors> tag, if any messages are required. Otherwise, ensure that the request attribute is not created.
  Parameters:
    `request` - The servlet request we are processing
    `errors` - Error messages object

### saveToken

    protected void saveToken(javax.servlet.http.HttpServletRequest request)

  Save a new transaction token in the user's current session, creating a new session if necessary.
  Parameters:
    `request` - The servlet request we are processing

### setLocale

    protected void setLocale(javax.servlet.http.HttpServletRequest request,
                             java.util.Locale locale)

  Set the user's currently selected Locale.
  Parameters:
    `request` - The request we are processing
    `locale` - The user's selected Locale to be set, or null to select the server's default Locale

### toHex

    protected java.lang.String toHex(byte[] buffer)

  Convert a byte array to a String of hexadecimal digits and return it.
  Parameters:
    `buffer` - The byte array to be converted

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2001 - Apache Software Foundation