public class MappingDispatchAction extends DispatchAction
An abstract Action that dispatches to a public method
that is named by the parameter
attribute of the corresponding
ActionMapping. This is useful for developers who prefer to combine many
related actions into a single Action class.
To configure the use of this action in your struts-config.xml
file, create an entry like this:
<action path="/saveSubscription"
type="org.example.SubscriptionAction"
name="subscriptionForm"
scope="request"
input="/subscription.jsp"
parameter="method"/>
where 'method' is the name of a method in your subclass of MappingDispatchAction that has the same signature (other than method name) of the standard Action.execute method. For example, you might combine the methods for managing a subscription into a single MappingDispatchAction class using the following methods:
for which you would create corresponding <action> configurations that reference this class:
<action path="/createSubscription"
type="org.example.SubscriptionAction"
parameter="create">
<forward name="success" path="/editSubscription.jsp"/>
</action>
<action path="/editSubscription"
type="org.example.SubscriptionAction"
parameter="edit">
<forward name="success" path="/editSubscription.jsp"/>
</action>
<action path="/saveSubscription"
type="org.example.SubscriptionAction"
parameter="save"
name="subscriptionForm"
validate="true"
input="/editSubscription.jsp"
scope="request">
<forward name="success" path="/savedSubscription.jsp"/>
</action>
<action path="/deleteSubscription"
type="org.example.SubscriptionAction"
name="subscriptionForm"
scope="request"
input="/subscription.jsp"
parameter="delete">
<forward name="success" path="/deletedSubscription.jsp"/>
</action>
<action path="/listSubscriptions"
type="org.example.SubscriptionAction"
parameter="list">
<forward name="success" path="/subscriptionList.jsp"/>
</action>
NOTE - Unlike DispatchAction, mapping characteristics may differ between the various handlers, so you can combine actions in the same class that, for example, differ in their use of forms or validation. Also, a request parameter, which would be visible to the application user, is not required to enable selection of the handler method.
clazz, methods, types
messages
Constructor and Description |
---|
MappingDispatchAction() |
Modifier and Type | Method and Description |
---|---|
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).
|
protected String |
getMethodName(ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String parameter)
Returns the method name, given a parameter's value.
|
protected String |
getParameter(ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Returns the parameter value.
|
protected ActionForward |
unspecified(ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Method which is dispatched to when there is no value for the parameter
in the ActionMapping.
|
cancelled, dispatchMethod, getMethod
addErrors, addMessages, execute, generateToken, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
public ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
ActionForward
instance describing where and how
control should be forwarded, or null
if the response has
already been completed.
This method dispatches the request to other methods of
MappingDispatchAction
using the 'parameter' attribute of
ActionMapping
and Java Introspection.execute
in class DispatchAction
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 creatingActionForward
instance describing where
and how control should be forwarded, or null
if
the response has already been completed.Exception
- if an exception occursprotected ActionForward unspecified(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
MappingDispatchAction
should override this method if they wish to provide default behavior
different than throwing a ServletException.unspecified
in class DispatchAction
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 creatingActionForward
instance describing where
and how control should be forwarded, or null
if
the response has already been completed.Exception
- if an exception occursprotected String getParameter(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
Returns the parameter value.
getParameter
in class DispatchAction
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 creatingActionMapping
parameter's valueException
- if the parameter is missing.protected String getMethodName(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String parameter) throws Exception
getMethodName
in class DispatchAction
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 creatingparameter
- The ActionMapping
parameter's nameException
- if an error occursCopyright © 2000–2017 Apache Software Foundation. All rights reserved.