What are different types of Actions we have in Struts?

There are seven type of Action in struts and each have their own relevance and importance, Here we will discuss each and everyone, Please find below all of them:

  • Action
  • Include
  • Forward
  • Switch
  • Dispatch
  • LookupDispatch
  • MappingDispatch

Action Class:
Action is a simple action which extend Action Class and overri3de an execute method which is called by default when request calls the specific action. Below is the Code to create a class with xml(struts-config.xml) entery:

public final class SimpleActionExample extends Action {

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

DispatchAction: DispatchAction is a action class, which extent the DispatchAction Class as stated below:

public final class ExampleDispatchAction extends DispatchAction {

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

struts-config.xml entry would be like below:

<action path= “/exampleDispatchAction” type= “com.bhanuapp.ExampleDispatchAction” name=”formName””” scope= request input= “homeDef” parameter= “ActionName” >
<forward name= “success” path= “example/ActionTartget.jsp” />
</action>

In View Layer like jsp call this action as follows:

<html:link action=”exampleDispatchAction?ActionName=create” >Create</html:link>