struts中合并多个Action用DispatchAction
建一个继承自DispatchAction的Action即可:
package blog;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
public class CRUDStudentAction extends DispatchAction {
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
PrintWriter out = response.getWriter();
out.println("delete operation");
return null;
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
PrintWriter out = response.getWriter();
out.println("add operation");
return null;
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
PrintWriter out = response.getWriter();
out.println("update operation");
return null;
}
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
PrintWriter out = response.getWriter();
out.println("insert operation");
return null;
}
}
在struts配置文件中加入:
<action-mappings>
<action path="/CRUDStudent" type="cn.itcast.CRUDStudentAction" parameter="operation"></action>
</action-mappings>
访问方式:
http://localhost:8080/strutstest3/CRUDStudent.do?operation=update