在这种写法中继承的是DispatchAction,它包含Action。
通过这种方式使程序结构显得清晰。
例如:
public class DispatchTestAction extends DispatchAction {
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
TestForm thisForm =(TestForm) actionForm;
if(thisForm.getMethod()==null){
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
TestForm thisForm =(TestForm) actionForm;
if(thisForm.getMethod()==null){
return null;
} else{
return dispatchMethod(actionMapping,actionForm,httpServletRequest,httpServletResponse,
} else{
return dispatchMethod(actionMapping,actionForm,httpServletRequest,httpServletResponse,
thisForm.getMethod() );
//通过接收方法名,进行分发到不同的处理中去
}
}
}
public ActionForward printMessage(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
System.out.println("===this is the method named printMessage====");
return actionMapping.findForward("success");
}
public ActionForward printAlert(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
System.out.println("====this is the method named printAlert====");
return null;
}
}
System.out.println("====this is the method named printAlert====");
return null;
}
}
本文介绍了一种基于DispatchAction的编程模式,该模式继承自DispatchAction并包含Action,通过实例演示了如何利用这种方法来实现请求的分发处理,使得程序结构更为清晰。
5698

被折叠的 条评论
为什么被折叠?



