command pattern within struts action class


Web tier: servlets, JSP, Web frameworks: command pattern within struts action class

  1. command pattern within struts action class (2 messages)

    I have an struts action class,that handles 100s of commands like,

     public class MyAction extends Action{

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

        String command=request.getParameter("command");

          //call to businees methods
        }else if(command.equals("02")){
         //call to businees methods
        else if(command.equals("100")){
         //call to businees methods

    Anyone suggest some good solution to avoid nestedif conditions?
  2. Hi Saravanan,

    There's a special Action subclass designed to handle this problem. It receives a parameter defined by you, which informs the command to be executed, and calls a method with the same name of that parameter. All you have to do is to implement the corresponding methods.

    Take a look at:
  3. better subclass lookupdispatchaction[ Go to top ]

    Dispatch action require client side javascript so use LookUpDisPachAction instead as it use a dispatching serverside map instead of client side javascript