如下面所示:<action name="webnewsForm"  validate="false" type="XXX.XXX.XX" scope="request" path="/jsp/web/news/index">
      <forward name="index" path="index.jsp" />
    </action><action name="webnewsForm"  validate="true" type="XXX.XXX.XX" scope="request" path="/jsp/web/news/index?action=add"  input="saveWebnews">
      <forward name="add" path="/jsp/web/news/add.jsp" />
      <forward name="error" path="/jsp/util/error.jsp" />
      <forward name="success" path="/jsp/util/success.jsp" />
    </action>注意path,前面的一样,只是一个有参数action,另一个没有,该如何去配啊?

解决方案 »

  1.   

    使用一个/jsp/web/news/index就可以了
    访问的时候用两个路径:
    /jsp/web/news/index.do
    /jsp/web/news/index.do?action=add
    然后你在execute中判断action的值,然后进行操作
    String action = request.getParameter("action");
    if(action == null){
      //你的第一种请求情况
    }
    else if(action.equals("add"){  //第二种情况
    }
    else...如果你使用struts的dispatch高级特性,可以在Action类中写多个方法,然后通过前台传入的参数自动调用不同的方法。
      

  2.   

    不要使用Action,用DispatchAction。不用写execute方法。只写不同的业务逻辑方法。例如
    public ActionForward register(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception{}
    struts-config.xml的配置方法:
    <action scope="request" path="/dosomethine" parameter="cmd" type="..." ... />
    调用的时候用/dosomething?cmd=register,就会自动执行register方法。