How many types of action clases are there in stuts?their uses?

Showing Answers 1 - 19 of 19 Answers

Kunal Krishna

  • Jun 8th, 2006
 

Apart from Action Class these are the following Action clases which you'ld find in Struts Framework ::::::::::::::

1)Dispatch Action :----- It dispatches to a public method that is named by the request parameter whose name is specified by the parameter property of the corresponding ActionMapping. This Action is useful for developers who prefer to combine many similar actions into a single Action class, in order to simplify their application design.

2)Forward Action :----------It forwards to the context-relative URI specified by the parameter property of our associated ActionMapping.

3)IncludeAction :-----------It includes the context-relative URI specified by the parameter property of our associated ActionMapping.

and there are more actions but these are the main actions which you developers mainly use in your daiyl codings...........

  Was this answer useful?  Yes

Mohan Brundavanam

  • Jul 14th, 2006
 

Types of Actions

1. Action.

2.DispachAction.

3.MappingDispatchAction.

4.LookUpDispatchAction.

  Was this answer useful?  Yes

Narayana

  • Jul 15th, 2006
 

Action -- As all know basic action class in which we will implement our bussiness logic

Include Action-- Similar to Include in our jsp

Forward Action-- Instead of directly forwarding from one JSP to Another We user Forward Action (If we do that directly it violates Struts MVC Architechture).

Dispatch Action-- Handling multiple operations in multiple methods. one method per operation instead of merging the entire logic in single execute method of action class.

Look up Dispatch Action-- Purpose is Similar to Dispatch action.Implementation is different Recommended not to use this.

Switch Action-- to switch between different modules in struts application

  Was this answer useful?  Yes

sreenivas

  • Sep 15th, 2006
 

Hi All,

There are 5 Actions classes in Struts,

1.Forward

2.Include

3.Dispatch

4.LookUpDispatch and

5.switch

  Was this answer useful?  Yes

santosh shetgar

  • Oct 17th, 2006
 

THERE ARE FOUR TYPES.

 

1)

DispatchAction: In this type of aggregation, the action class must extend DispatchAction class as shown.

public final class CRUDDispatchAction extends DispatchAction {

public ActionForward create(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return (mapping.findForward("success"));
}
... 


and the action mapping will be as 

<action path="/crudDispatchAction" type="com.companyname.projname.CRUDDispatchAction" name="formName" scope="request" input=" homeDef" parameter="methodToCall">
<forward name="success" path="targetDefName"/>
</action>


in your jsp you can call this action as 

<html:link action="crudDispatchAction?methodToCall=create">Create</html:link>
... 


Observe that the above class extends DispatchAction and so you cannot use this method if your class already extends your (some) super class (eg., the class where the session is validated/invalidated). Here the user has to send a query string variable (methodToCall) to set the action name to call.

2)

 

ActionDispatcher: This flavor of aggregation is same as DispatchAction except that we need not extend ActionDispatcher, so we can use this method even if our class extends a super class. The following code snippet shows this scenario.


public final class CRUDActionDispatcher extends Action {

protected ActionDispatcher dispatcher = new ActionDispatcher(this, ActionDispatcher.DEFAULT_FLAVOR);

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return dispatcher.execute(mapping, form, request, response);
}
The DEFAULT_FLAVOR field suggests that the default parameter is "method" if none is specified as parameter in struts-config.xml (eg,. methodToCall).
ActionDispatcher flavor also needs methodToCall parameter to be set (using hidden variable or a query string) as in case of DispatchAction.

 

3)

 

LookupDispatchAction: This type of aggregation is useful in situations where in you have multiple submit buttons in a single form. The class must extend LookupDispatchAction. However, the great thing about this type is that its java script free. That means, you need not set any hidden variables or pass query string however, you must use submit buttons as shown.

<html:submit property="submit"><bean:message key="button.create"/></html: submit >
<html:submit property="submit"><bean:message key="button.read"/></html: submit >
... 
The example Action class will be as follows 

public class CRUDLookUpDispatchAction extends LookupDispatchAction {

protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.create", "create");

return map;
}
public ActionForward create(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return (mapping.findForward("success"));
}
Observe the getKeyMethodMap() method. The submit button names are specified in a Map and their keys comes from MessageResources file. Struts picks up the name from this file and redirects it to the value specified in the Map. The calling code in jsp however has multiple submit buttons only differing in their names.

 

4)

 

MappingDispatchAction: This aggregation extends MappingDispatchAction class. This is the most useful type among the four types available. But as seen in other cases, you can use this type only when your action does not extend any other action. The good thing about this type is that the action mappings can differ and so need not be the same as in all other cases. To illustrate this consider the below mappings.

<action path="/createMappingAction" type="com.bodhtree.CRUDMappingDispatchAction" scope="request" input="homeDef" parameter="create">
<forward name="success" path="targetDef"/>
</action>
<action path="/readMappingAction" type="com.bodhtree.CRUDMappingDispatchAction" name=" formName" scope="request" input="homeDef" parameter=" read">
<forward name="success" path="targetDef"/>
</action> 


Notice that in the first action mapping, there is no form bean while in the second the bean name is specified. This means that the user has the flexibility to change the mapping according to his needs and hence not been contained to use a constant mapping for all the CRUD actions. Note that in all the other types of aggregations, we must use the same mapping for all the CRUD actions.

  Was this answer useful?  Yes

santosh shetgar

  • Oct 17th, 2006
 

The important Dispatchers that struts provides includes : DispatchAction, ActionDispatcher , LookupDispatchAction and MappingDispatchAction.

DispatchAction: In this type of aggregation, the action class must extend DispatchAction class as shown.

public final class CRUDDispatchAction extends DispatchAction {

public ActionForward create(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return (mapping.findForward("success"));
}
... 


and the action mapping will be as 

<action path="/crudDispatchAction" type="com.companyname.projname.CRUDDispatchAction" name="formName" scope="request" input=" homeDef" parameter="methodToCall">
<forward name="success" path="targetDefName"/>
</action>


in your jsp you can call this action as 

<html:link action="crudDispatchAction?methodToCall=create">Create</html:link>
... 


Observe that the above class extends DispatchAction and so you cannot use this method if your class already extends your (some) super class (eg., the class where the session is validated/invalidated). Here the user has to send a query string variable (methodToCall) to set the action name to call.

ActionDispatcher: This flavor of aggregation is same as DispatchAction except that we need not extend ActionDispatcher, so we can use this method even if our class extends a super class. The following code snippet shows this scenario.


public final class CRUDActionDispatcher extends Action {

protected ActionDispatcher dispatcher = new ActionDispatcher(this, ActionDispatcher.DEFAULT_FLAVOR);

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return dispatcher.execute(mapping, form, request, response);

The DEFAULT_FLAVOR field suggests that the default parameter is "method" if none is specified as parameter in struts-config.xml (eg,. methodToCall).
ActionDispatcher flavor also needs methodToCall parameter to be set (using hidden variable or a query string) as in case of DispatchAction.

LookupDispatchAction: This type of aggregation is useful in situations where in you have multiple submit buttons in a single form. The class must extend LookupDispatchAction. However, the great thing about this type is that its java script free. That means, you need not set any hidden variables or pass query string however, you must use submit buttons as shown.


<html:submit property="submit"><bean:message key="button.create"/></html: submit >
<html:submit property="submit"><bean:message key="button.read"/></html: submit >
... 
The example Action class will be as follows 

public class CRUDLookUpDispatchAction extends LookupDispatchAction {

protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.create", "create");

return map;
}
public ActionForward create(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return (mapping.findForward("success"));
}
Observe the getKeyMethodMap() method. The submit button names are specified in a Map and their keys comes from MessageResources file. Struts picks up the name from this file and redirects it to the value specified in the Map. The calling code in jsp however has multiple submit buttons only differing in their names.

MappingDispatchAction: This aggregation extends MappingDispatchAction class. This is the most useful type among the four types available. But as seen in other cases, you can use this type only when your action does not extend any other action. The good thing about this type is that the action mappings can differ and so need not be the same as in all other cases. To illustrate this consider the below mappings.

<action path="/createMappingAction" type="com.bodhtree.CRUDMappingDispatchAction" scope="request" input="homeDef" parameter="create">
<forward name="success" path="targetDef"/>
</action>
<action path="/readMappingAction" type="com.bodhtree.CRUDMappingDispatchAction" name=" formName" scope="request" input="homeDef" parameter=" read">
<forward name="success" path="targetDef"/>
</action> 


Notice that in the first action mapping, there is no form bean while in the second the bean name is specified. This means that the user has the flexibility to change the mapping according to his needs and hence not been contained to use a constant mapping for all the CRUD actions. Note that in all the other types of aggregations, we must use the same mapping for all the CRUD actions.

  Was this answer useful?  Yes

Abbie

  • Aug 1st, 2007
 

There are basically 2 main actions-
1) Bridge Actions->it contains 1. ForwardAction and IncludeAction
2) Base Actions -> DispatchAction,LookupDispatchAction,SwitchAction and BaseAction.

  Was this answer useful?  Yes

Remija

  • Nov 15th, 2007
 

There are 7 types they are,

1.Forward Action
2.Dispatch Action
3.include Action
4.lookUpDispatch Actioc
5.MappingDispatch Action
6.switch Action
7.LocaleDispatch Action

  Was this answer useful?  Yes

There are fine different types of actions in the struts


i) Forward Action (to forward a request to another resource in your
application)
ii) Include Action ( To include some action )


You Might be wondering what the difference between Forward Action and Include
Action so here it is : The difference is that you need to use the IncludeAction
only if the action is going to be included by another action or JSP. Use
ForwardAction to forward a request to another resource in your application, such
as a Servlet that already does business logic processing or even another JSP
page.


iii) Dispatch Action ( to group related actions into one class)
iv) Lookup Dispatch Action (is useful if the method name in the Action is not
driven by its name in the front end, but by the Locale independent key into the
resource bundle.)


The difference between LookupDispatchAction and DispatchAction is that the
actual method that gets called in LookupDispatchAction is based on a lookup of a
key value instead of specifying the method name directly.


v) Switch Action (The SwitchAction class provides a means to switch from a
resource in one module to another resource in a different module. SwitchAction
is useful only if you have multiple modules in your Struts application. The
SwitchAction class can be used as is, without extending.)


  Was this answer useful?  Yes

nandana

  • Jul 19th, 2011
 

there are 9 action classes are there
1.action
2.dispatch action
3.mapping dispatch action
4.lookup dispatch action
5.include action
6.forward action
7.switch action
8.locate action
9.download action

  Was this answer useful?  Yes

prasanth

  • Nov 24th, 2011
 

i think in struts1.x we are having 7 action classes

1.DispatchAction
2.ForwardAction
3.IncludeAction
4.MappingDispatchAction
5.LocalAction
6.SwitchAction
7.LookupDispatchAction

and i don't know about ActionDispatcher.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions