java

位置:IT落伍者 >> java >> 浏览文章

struts中dispathAction


发布日期:2022年08月11日
 
struts中dispathAction

当在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方法删除!!!

上一篇:Spring事务深入浅出

下一篇:Spring Batch 2将支持工作划分和基于注解的配置