Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.struts.action.Action
public class Action
extends java.lang.Object
execute
method.
Actions must be programmed in a thread-safe manner, because the
controller will share the same instance for multiple simultaneous
requests. This means you should design with the following items in mind:
Action
instance is first created, the controller
will call setServlet
with a non-null argument to
identify the servlet instance to which this Action is attached.
When the 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.
Field Summary | |
protected static Locale |
|
protected ActionServlet |
|
private static TokenProcessor |
|
Method Summary | |
protected void |
|
protected void |
|
ActionForward |
|
ActionForward |
|
protected String |
|
protected DataSource |
|
protected DataSource |
|
protected ActionMessages |
|
protected Locale |
|
protected ActionMessages |
|
protected MessageResources |
|
protected MessageResources |
|
ActionServlet |
|
protected boolean |
|
protected boolean |
|
protected boolean |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
void |
|
protected static Locale defaultLocale
Deprecated. Use Locale.getDefault directly. This will be removed after Struts 1.2.
The system default Locale.
private static TokenProcessor token
An instance ofTokenProcessor
to use for token functionality.
protected void addErrors(HttpServletRequest request, ActionMessages errors)
Adds the specified errors keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. Initialize the attribute if it has not already been. Otherwise, ensure that the request attribute is not set.
- Parameters:
request
- The servlet request we are processingerrors
- Errors object
- Since:
- Struts 1.2.1
protected void addMessages(HttpServletRequest request, ActionMessages messages)
Adds the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. Initialize the attribute if it has not already been. Otherwise, ensure that the request attribute is not set.
- Parameters:
request
- The servlet request we are processingmessages
- Messages object
- Since:
- Struts 1.2.1
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. Return anActionForward
instance describing where and how control should be forwarded, ornull
if the response has already been completed.
- Parameters:
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The HTTP request we are processingresponse
- The HTTP response we are creating
- Since:
- Struts 1.1
public ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) throws Exception
Process the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. Return anActionForward
instance describing where and how control should be forwarded, ornull
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 instanceform
- The optional ActionForm bean for this request (if any)request
- The non-HTTP request we are processingresponse
- The non-HTTP response we are creating
- Since:
- Struts 1.1
protected String generateToken(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
protected DataSource getDataSource(HttpServletRequest request)
Return the default data source for the current module.
- Parameters:
request
- The servlet request we are processing
- Since:
- Struts 1.1
protected DataSource getDataSource(HttpServletRequest request, String key)
Return the specified data source for the current module.
- Parameters:
request
- The servlet request we are processingkey
- The key specified in the<data-sources>
element.
- Since:
- Struts 1.1
protected ActionMessages getErrors(HttpServletRequest request)
Retrieves any existing errors placed in the request by previous actions. This method could be called instead of creating anew ActionMessages()
at the beginning of an
Action
This will prevent saveErrors() from wiping out any existing Errors
- Parameters:
request
- The servlet request we are processing
- Returns:
- the Errors that already exist in the request, or a new ActionMessages object if empty.
- Since:
- Struts 1.2.1
protected Locale getLocale(HttpServletRequest request)
Return the user's currently selected Locale.
- Parameters:
request
- The request we are processing
protected ActionMessages getMessages(HttpServletRequest request)
Retrieves any existing messages placed in the request by previous actions. This method could be called instead of creating anew ActionMessages()
at the beginning of an
Action
This will prevent saveMessages() from wiping out any existing Messages
- Parameters:
request
- The servlet request we are processing
- Returns:
- the Messages that already exist in the request, or a new ActionMessages object if empty.
- Since:
- Struts 1.2.1
protected MessageResources getResources(HttpServletRequest request)
Return the default message resources for the current module.
- Parameters:
request
- The servlet request we are processing
- Since:
- Struts 1.1
protected MessageResources getResources(HttpServletRequest request, String key)
Return the specified message resources for the current module.
- Parameters:
request
- The servlet request we are processingkey
- The key specified in the<message-resources>
element for the requested bundle
- Since:
- Struts 1.1
protected boolean isCancelled(HttpServletRequest request)
Returnstrue
if the current form's cancel button was pressed. This method will check if theGlobals.CANCEL_KEY
request attribute has been set, which normally occurs if the cancel button generated by CancelTag was pressed by the user in the current request. Iftrue
, validation performed by an ActionForm'svalidate()
method will have been skipped by the controller servlet.
- Parameters:
request
- The servlet request we are processing
- See Also:
CancelTag
protected boolean isTokenValid(HttpServletRequest request)
Returntrue
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. Returnsfalse
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
protected boolean isTokenValid(HttpServletRequest request, boolean reset)
Returntrue
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. Returnsfalse
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 processingreset
- Should we reset the token after checking it?
protected void resetToken(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
protected void saveErrors(HttpServletRequest request, ActionErrors errors)
Deprecated. Use saveErrors(HttpServletRequest, ActionMessages) instead. This will be removed after Struts 1.2.
Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. Otherwise, ensure that the request attribute is not created.
- Parameters:
request
- The servlet request we are processingerrors
- Error messages object
protected void saveErrors(HttpServletRequest request, ActionMessages errors)
Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. Otherwise, ensure that the request attribute is not created.
- Parameters:
request
- The servlet request we are processingerrors
- Error messages object
- Since:
- Struts 1.2
protected void saveErrors(HttpSession session, ActionMessages errors)
Save the specified error messages keys into the appropriate session attribute for use by the <html:messages> tag (if messages="false") or <html:errors>, if any error messages are required. Otherwise, ensure that the session attribute is empty.
- Parameters:
session
- The session to save the error messages in.errors
- The error messages to save.null
or empty messages removes any existing error ActionMessages in the session.
- Since:
- Struts 1.2.7
protected void saveMessages(HttpServletRequest request, ActionMessages messages)
Save the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. Otherwise, ensure that the request attribute is not created.
- Parameters:
request
- The servlet request we are processing.messages
- The messages to save.null
or empty messages removes any existing ActionMessages in the request.
- Since:
- Struts 1.1
protected void saveMessages(HttpSession session, ActionMessages messages)
Save the specified messages keys into the appropriate session attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. Otherwise, ensure that the session attribute is not created.
- Parameters:
session
- The session to save the messages in.messages
- The messages to save.null
or empty messages removes any existing ActionMessages in the session.
- Since:
- Struts 1.2
protected void saveToken(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
protected void setLocale(HttpServletRequest request, Locale locale)
Set the user's currently selectedLocale
into theirHttpSession
.
- Parameters:
request
- The request we are processinglocale
- The user's selected Locale to be set, or null to select the server's default Locale
public void setServlet(ActionServlet servlet)
Set the servlet instance to which we are attached (ifservlet
is non-null), or release any allocated resources (ifservlet
is null).
- Parameters:
servlet
- The new controller servlet, if any