(省略掉execute 里面的 if else if()等等 一系列判断 从而在struts config-里 配置parameter 进行判断)
让 Action 继承 DispatchAction
可以 省略 在 Aciton 的判断 type
Useraction extends DispatchAction{
}
---------------------------------------------------------------------------------------------------------------------------
这里一定 要去掉 execute(mapping,form,request,response) 方法..
如果不去掉这个方法的话 就会 一直先调用这个方法
public class Useraction extends DispatchAction {
public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("insert=========="); return new ActionForward("/index.jsp"); } public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("delete=========="); return new ActionForward("/index.jsp"); }
这个方法直接写 public ActionForward insert(mapping,form,request,response)方法
而 Struts - config .xml 里 配置
<action path="/Useraction" type="com.user.action.Useraction" parameter="type"></action></action-mappings>
---------------------------------------------------------------------------------------------------------------------------------
parameter 是根据
<a href="Useraction.do?type=insert">insert</a>
<a href="Useraction.do?type=delete">delete</a>