如和在Struts1中一个Action实现多个业务逻辑,怎么样实现会比较好些

解决方案 »

  1.   

    给你们看看我的代码  JSP的:
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    response.sendRedirect("dispStudent.do?method=dispStudent");
    %>
    Action配置文件
    <action  path="/dispStudent"
           parameter="method"
            attribute="studentForm"
           name="studentForm"
           type="com.Struts1.Action.StudentAction"
     >
           <forward name="success" path="/index.jsp" />
        </action> Action类
    package com.Struts1.Action;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 StudentAction extends DispatchAction {
    public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
    HttpServletRequest request, HttpServletResponse response) throws Exception {// String method = request.getParameter("method");
    //
    // if("dispStudent".equals(method))
    // this.dispStudent(mapping, actionForm, request, response);
    System.out.println("ccccccccc");
    return mapping.findForward("");
    } //显示所有的学生信息
    public ActionForward dispStudent(ActionMapping mapping, ActionForm actionForm,
    HttpServletRequest request, HttpServletResponse response) throws Exception {

    System.out.println("ddddddddddd");
    return mapping.findForward("success");
    }
    }
      

  2.   

    现在时我运行  上面得JSP代码的时候就跳转的这个地址 然后就没有反应了。http://localhost:8088/Struts1/dispStudent.do?method=dispStudent
      

  3.   

    你确认转到指定的action了吗,如果转到了指定的action应该可以转到指定的页面,如果不能转到指定的action,你看下你的连接或者是表单,这里常常可能因为单引号或者双引号就会引起错误。
      

  4.   

    你用DispatchAction 的时候不能使用execute方法,不然它只会进到这个方法里面的,不管你写了多少其他方法都没有!把这个execute的名字改掉吧!
      

  5.   

    恩处理好了,去掉execute方法了,如果加这个方法的话,应该调用一下父类的execute方法吧
      

  6.   

    要把execute方法名字改成其他方法名,然后在配置文件对应的action中增加parameter属性,值为方法名,也可以继承
    MappingDispatchAction,这个更好用!
      

  7.   

    我的理解是让一个action实现多个业务逻辑,如果是这样的话,可不可以这样?
    绑定的from里,添加一个actionType属性
    在提交时,添加actionType的属性
    然后在action中,可以添加
    String strActionType = form.getActionType();
    if("Init".equals(strActionType)){
       //TODO:执行从菜单进入该action的操作
    }else if("Edit".equals(strActionType)){
       //TODO:编辑...
    }.....
      

  8.   

    我就是使用DispacAction的,配置文件,什么都是好的,为什么就是不进action。谁有关于这个的例子,分享下,给我看看。谢谢啦