DispatchAction是struts 1 的内置通用分发器
import org.apache.struts.actions.DispatchAction; public class UserAction extends DispatchAction { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throwsException { //调用业务逻辑操作 //一定要执行这句话,或者干脆把execute()方法去掉 return super.execute(); } public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throwsException { //调用业务逻辑操作 return mapping.findForward("list_success"); } public ActionForward del(ActionMappingmapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { //调用业务逻辑操作 return mapping.findForward("del_success"); } public ActionForward add(ActionMappingmapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throwsException { //调用业务逻辑操作 return mapping.findForward("add_success"); } }
上面这个Action有三个跟业务相关的方法list()、add()、del();Struts将请求转入这个Action之后,会根据一个参数名称来决定要执行哪个方法,这个参数的名字和Action内的方法名字一致,这个参数需要在<action-mapping>中配置,一般为action或method
<action name="firstForm" path="/user" parameter="method" <!-- 分发器参数--> type="com.clf.struts.action.HelloAction" />
原文地址:http://blog.csdn.net/u012152619/article/details/43266133