11 June, 2012

Java Struts: The flavor of DispatchAction. Leave Action and Love DispatchAction .

Its really good to know that struts has so many features which provides the programmer/developer easy life.Out of all the good thing the action part of struts frame work is superb. As you know there are 5 type of action , provided by struts.

But the Dispatch action make your job function centric. Struts DispatchAction from (org.apache.struts.actions.DispatchAction) is one of the Built-in Actions provided along with the struts framework.It works on a single action with multiple function . No need of create multiple action type for operating any task. It gather all related methods into a single.

An abstract Action that 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. Read more on this Dispatch Action.


public class MyDispatch_Action extends DispatchAction
 

{
  

public ActionForward add-data(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) throws Exception{
  System.out.println("You are inside add");
  return mapping.findForward("addmydata");
  }

  

public ActionForward edit-data(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) throws Exception

 {

  System.out.println("You are inside edit");
    return mapping.findForward("editmydata");
  

 }




return null;

}




The rest are same flavor as other struts.Just enjoy new flavor.

No comments:

Post a Comment