|
|||||||||
| Home >> All >> org >> apache >> struts >> [ action overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.struts.action
Class Action

java.lang.Objectorg.apache.struts.action.Action
- 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 (RequestProcessor) will select an
appropriate Action for each request, create an instance (if necessary),
and call the 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:
- 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
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.
- Version:
- $Rev: 164530 $ $Date: 2005-04-25 04:11:07 +0100 (Mon, 25 Apr 2005) $
| Field Summary | |
protected static java.util.Locale |
defaultLocale
Deprecated. Use Locale.getDefault directly. This will be removed after Struts 1.2. |
protected ActionServlet |
servlet
The servlet to which we are attached. |
private static org.apache.struts.util.TokenProcessor |
token
An instance of TokenProcessor to use for token functionality. |
| Constructor Summary | |
Action()
|
|
| Method Summary | |
protected void |
addErrors(javax.servlet.http.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. |
protected void |
addMessages(javax.servlet.http.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. |
ActionForward |
execute(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), with provision for handling exceptions thrown by the business logic. |
ActionForward |
execute(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), with provision for handling exceptions thrown by the business logic. |
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 javax.sql.DataSource |
getDataSource(javax.servlet.http.HttpServletRequest request)
Return the default data source for the current module. |
protected javax.sql.DataSource |
getDataSource(javax.servlet.http.HttpServletRequest request,
java.lang.String key)
Return the specified data source for the current module. |
protected ActionMessages |
getErrors(javax.servlet.http.HttpServletRequest request)
Retrieves any existing errors placed in the request by previous actions. |
protected java.util.Locale |
getLocale(javax.servlet.http.HttpServletRequest request)
Return the user's currently selected Locale. |
protected ActionMessages |
getMessages(javax.servlet.http.HttpServletRequest request)
Retrieves any existing messages placed in the request by previous actions. |
protected org.apache.struts.util.MessageResources |
getResources(javax.servlet.http.HttpServletRequest request)
Return the default message resources for the current module. |
protected org.apache.struts.util.MessageResources |
getResources(javax.servlet.http.HttpServletRequest request,
java.lang.String key)
Return the specified message resources for the current module. |
ActionServlet |
getServlet()
Return the 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. |
protected boolean |
isTokenValid(javax.servlet.http.HttpServletRequest request,
boolean reset)
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. |
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)
Deprecated. Use saveErrors(HttpServletRequest, ActionMessages) instead. This will be removed after Struts 1.2. |
protected void |
saveErrors(javax.servlet.http.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. |
protected void |
saveErrors(javax.servlet.http.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. |
protected void |
saveMessages(javax.servlet.http.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. |
protected void |
saveMessages(javax.servlet.http.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. |
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 into their
HttpSession. |
void |
setServlet(ActionServlet servlet)
Set the servlet instance to which we are attached (if servlet is non-null), or release any allocated resources
(if servlet is null). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
token
private static org.apache.struts.util.TokenProcessor token
An instance of
TokenProcessorto use for token functionality.
defaultLocale
protected static java.util.Locale defaultLocale
- Deprecated. Use Locale.getDefault directly. This will be removed after
Struts 1.2.
The system default Locale.
servlet
protected ActionServlet servlet
The servlet to which we are attached.
| Constructor Detail |
Action
public Action()
| Method Detail |
getServlet
public ActionServlet getServlet()
Return the servlet instance to which we are attached.
setServlet
public void setServlet(ActionServlet servlet)
Set the servlet instance to which we are attached (if
servletis non-null), or release any allocated resources (ifservletis null).
execute
public ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws java.lang.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 an ActionForward instance describing where and how control should be forwarded, or
nullif the response has already been completed.The default implementation attempts to forward to the HTTP version of this method.
- Since:
- Struts 1.1
execute
public ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.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 an ActionForward instance describing where and how control should be forwarded, or
nullif the response has already been completed.- Since:
- Struts 1.1
addMessages
protected void addMessages(javax.servlet.http.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.
- Since:
- Struts 1.2.1
addErrors
protected void addErrors(javax.servlet.http.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.
- Since:
- Struts 1.2.1
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.
getDataSource
protected javax.sql.DataSource getDataSource(javax.servlet.http.HttpServletRequest request)
Return the default data source for the current module.
- Since:
- Struts 1.1
getDataSource
protected javax.sql.DataSource getDataSource(javax.servlet.http.HttpServletRequest request, java.lang.String key)
Return the specified data source for the current module.
- Since:
- Struts 1.1
getErrors
protected ActionMessages getErrors(javax.servlet.http.HttpServletRequest request)
- Retrieves any existing errors placed in the request by previous actions. This method could be called instead
of creating a
new ActionMessages()at the beginning of anActionThis will prevent saveErrors() from wiping out any existing Errors- Since:
- Struts 1.2.1
getLocale
protected java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)
Return the user's currently selected Locale.
getMessages
protected ActionMessages getMessages(javax.servlet.http.HttpServletRequest request)
- Retrieves any existing messages placed in the request by previous actions. This method could be called instead
of creating a
new ActionMessages()at the beginning of anActionThis will prevent saveMessages() from wiping out any existing Messages- Since:
- Struts 1.2.1
getResources
protected org.apache.struts.util.MessageResources getResources(javax.servlet.http.HttpServletRequest request)
Return the default message resources for the current module.
- Since:
- Struts 1.1
getResources
protected org.apache.struts.util.MessageResources getResources(javax.servlet.http.HttpServletRequest request, java.lang.String key)
Return the specified message resources for the current module.
- Since:
- Struts 1.1
isCancelled
protected boolean isCancelled(javax.servlet.http.HttpServletRequest request)
Returns
trueif the current form's cancel button was pressed. This method will check if theGlobals.CANCEL_KEYrequest 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.
isTokenValid
protected boolean isTokenValid(javax.servlet.http.HttpServletRequest request)
Return
trueif 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. Returnsfalseunder 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
isTokenValid
protected boolean isTokenValid(javax.servlet.http.HttpServletRequest request, boolean reset)
Return
trueif 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. Returnsfalseunder 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
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.
saveErrors
protected void saveErrors(javax.servlet.http.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.
saveErrors
protected void saveErrors(javax.servlet.http.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.
- Since:
- Struts 1.2
saveMessages
protected void saveMessages(javax.servlet.http.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.
- Since:
- Struts 1.1
saveMessages
protected void saveMessages(javax.servlet.http.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.
- Since:
- Struts 1.2
saveErrors
protected void saveErrors(javax.servlet.http.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.
- Since:
- Struts 1.2.7
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.
setLocale
protected void setLocale(javax.servlet.http.HttpServletRequest request, java.util.Locale locale)
Set the user's currently selected
Localeinto theirHttpSession.
|
|||||||||
| Home >> All >> org >> apache >> struts >> [ action overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.struts.action.Action