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