几种DispatchAction的不同之处
来源:优易学  2011-12-7 14:17:30   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  在Action中要有相应的方法:

  public class SubscriptionAction extends LookupDispatchAction {

  public ActionForward save(ActionMapping mapping,

  ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  public ActionForward back(ActionMapping mapping,

  ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  public ActionForward recalculate(ActionMapping mapping,

  ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  }

  MappingDispatchAction

  public class MappingDispatchAction extends DispatchAction

  它的相应方法的执行由ActionMapping中parameter名决定,注意这里和LookupDispatchAction不同,LookupDispatchAction的相应方法的执行由ActionMapping中parameter属性决定。

  struts-config.xml:

  <action path="/createSubscription" type="org.example.SubscriptionAction" parameter="create">

  <forward name="success" path="/createSubscription.jsp"/>

  </action>

  <action path="/editSubscription" type="org.example.SubscriptionAction" parameter="edit">

  <forward name="success" path="/editSubscription.jsp"/>

  </action>

  <action path="/saveSubscription" type="org.example.SubscriptionAction" parameter="save"

  name="subscriptionForm" validate="true" input="/editSubscription.jsp" scope="request">

  <forward name="success" path="/savedSubscription.jsp"/>

  </action>

  <action path="/deleteSubscription" type="org.example.SubscriptionAction" name="subscriptionForm"

  scope="request" input="/subscription.jsp" parameter="delete">

  <forward name="success" path="/deletedSubscription.jsp"/>

  </action>

  <action path="/listSubscriptions" type="org.example.SubscriptionAction" parameter="list">

  <forward name="success" path="/subscriptionList.jsp"/>

  </action>

  在Action中要有相应的方法:

  public class SubscriptionAction extends MappingDispatchAction {

  public ActionForward create(ActionMapping mapping, ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  public ActionForward edit(ActionMapping mapping, ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  public ActionForward save(ActionMapping mapping, ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  public ActionForward delete(ActionMapping mapping, ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  public ActionForward list(ActionMapping mapping, ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response) throws Exception {}

  }

  然后可以通过这样的方法来访问你的程序:

  http://localhost:8080/myapp/create.do

  http://localhost:8080/myapp/edit.do

  http://localhost:8080/myapp/save.do

  http://localhost:8080/myapp/delete.do

  http://localhost:8080/myapp/list.do

  如果parameter中参数为空,则调用Action中的unspecified方法

上一页  [1] [2] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训