在设计时发现对一个对象进行增、查、改所需的表单相同,三种业务页面完全可以使用同一个jsp来生成
通过parameter来判断操作类型,生成所需页面或执行相应操作。准备在指向页面前通过一个预备Action来做准备工作,
具体操作流程 to_edit_emp.do-->toEditEmpAction-->edit_emp.jsp(业务页面)不这么做的话,一样的页面做三个实在是不方便维护,
请教下这种设计方法有什么不妥的地方么?预备Action的代码:public final class ToEditEmpAction extends Action {    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
String action = request.getParameter("action");
ActionForward forward = new ActionForward();
if(action.equals("insert")){
    forward = toInsert(mapping,form,request,response);
}else if(action.equals("edit")){
    forward = toEdit(mapping,form,request,response);
}else if(action.equals("view")){
    forward = toView(mapping,form,request,response);
}
return forward;
    }    private ActionForward toInsert(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
return null;
    }
    
    private ActionForward toEdit(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
return null;
    }
    
    private ActionForward toView(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
return null;
    }
}

解决方案 »

  1.   

    这回复真是神速啊大家还有没别的看法,struts把业务逻辑放在xml里方便了管理,现在我再把部分放回Action里好像就有些违背struts的本意了……
      

  2.   

    用DispatchAction 不可以吗?
      

  3.   

    支持使用Struts自带的分发Action: DispatchAction
      

  4.   

    同意3 、4 楼的说法,用DispatchAction就行了。
      

  5.   

    甚为不妥,没有面向对象的概念,导致分支条件与业务逻辑重合,如果以后再增加一个分支,这个代码还需要改动!public interface Dispatch {    public ActionForward doDispatch(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response);
    }public class InsertDispatch implements Dispatch {
        // implements Dispatch interface method
    }public class EditDispatch implements Dispatch {
        // implements Dispatch interface method
    }public class ViewDispatch implements Dispatch {
        // implements Dispatch interface method
    }