我的基类
public abstract class ActionBase extends Action {
public abstract Object init(ActionConfig actionConfig) throws Exception;
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException, SecurityException,
NoSuchMethodException, InvocationTargetException,Exception,
IllegalArgumentException, IllegalAccessException {
ActionForward actionForward = null;
String method = request.getParameter( "method ");
System.out.println(method);
String message = " ";
if(method == null){
method = " ";
}
//创建一个ActionConfig方法用来封装配置信息
ActionConfig actionCfg = new ActionConfig(mapping,form,request,response);
//得到当前类的对象
Class c = this.getClass();
System.out.println(c.getName());
//通过传过来的方法名(method)在它的子类中查找这个方法
Method methodName = c.getMethod(method,new Class[] {ActionConfig.class});
System.out.println(methodName.getName());
if(methodName == null){
message = "没有找到这个方法名! ";
actionCfg.getRequest().setAttribute( "message ",message);
actionCfg.getMapping().findForward( " ");
}
Object[] arg = {actionCfg};
//转入到方法名为methodName的方法中执行操作
actionForward = (ActionForward)methodName.invoke(this,arg);
return actionForward;
}
//public abstract ActionForward method(ActionConfig actionCfg);
}
封装ActionConfig信息的类:
public class ActionConfig {
private ActionMapping mapping;