熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

struts中dispathAction

2022-06-13   來源: Java開源技術 

  當在stuts中需要在一個action中定義多個方法時可以使用dispathAction來完成

  下面是測試的一個簡單的例子

  Action:

  //Created by MyEclipse Struts

  // XSL source (default): platform:/plugin/genuitececlipsecrosseasystrutseclipse_/xslt/JavaClassxsl

  package teststrutsaction;

  import javaxservlethttpHttpServletRequest;

  import javaxservlethttpHttpServletResponse;

  import orgapachestrutsactionActionForm;

  import orgapachestrutsactionActionForward;

  import orgapachestrutsactionActionMapping;

  import orgapachestrutsactionsDispatchAction;

  /**

  * MyEclipse Struts

  * Creation date:

  *

  * XDoclet definition:

  * @strutsaction parameter=method

  */

  public class MyDispathAction extends DispatchAction {

  // Instance Variables

  // Methods

  /**

  * Method execute

  * @param mapping

  * @param form

  * @param request

  * @param response

  * @return ActionForward

  */

  public ActionForward Add(

  ActionMapping mapping

  ActionForm form

  HttpServletRequest request

  HttpServletResponse response) {

  requestsetAttribute(method new String(add));

  return mappingfindForward(sucess);

  }

  public ActionForward Delete(

  ActionMapping mapping

  ActionForm form

  HttpServletRequest request

  HttpServletResponse response) {

  requestgetSession()setAttribute(method new String(delete));

  return mappingfindForward(sucess);

  }

  }

  stutsconfigxml:

  <action

  parameter=method

  path=/dispath

  type=comteststrutsactionMyDispathAction

  validate=false >

  <forward name=sucess path=/sucessjsp />

  </action>

  需要注意的是要將action中的execute方法刪除!!!


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28238.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.