我的基类
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;
private ActionForm form;
private HttpServletRequest request;
private HttpServletResponse response; public ActionConfig(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
this.mapping = mapping;
this.form = form;
this.request = request;
this.response = response;
} public ActionMapping getMapping(){
return mapping;
} public ActionForm getForm(){
return form;
} public HttpServletRequest getRequest(){
return request;
} public HttpServletResponse getResponse(){
return response;
}
}在的Action类:
public class LoginAction extends ActionBase {
com.book.util.Hibernate hbm=new com.book.util.Hibernate();
/** public ActionForward execute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)throws HibernateException,IOException {
public ActionForward performLogin(ActionConfig cfg) throws
HibernateException {
String target="suss";
System.out.println(target);
ActionErrors errors = new ActionErrors();
LoginForm loginForm = (LoginForm)cfg.getForm();
String username=loginForm.getUsername();
String psw=loginForm.getPsw();
if(!hbm.isLogin(username,psw)){
target="fail";
errors.add("loginError",new ActionError("error.logerror"));
saveErrors(cfg.getRequest(),errors);
}
else{
HttpSession session = cfg.getRequest().getSession();
session.setAttribute("username", username); }
return cfg.getMapping().findForward(target); }当输入...?method=performLogin 老是报错
javax.servlet.ServletException: struts.Action.RoleAction.performSyslist(struts.ActionConfig)
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.NoSuchMethodException: struts.Action.RoleAction.performSyslist(struts.ActionConfig)
java.lang.Class.getMethod(Class.java:1581)
struts.ActionBase.execute(ActionBase.java:39)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
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;
private ActionForm form;
private HttpServletRequest request;
private HttpServletResponse response; public ActionConfig(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
this.mapping = mapping;
this.form = form;
this.request = request;
this.response = response;
} public ActionMapping getMapping(){
return mapping;
} public ActionForm getForm(){
return form;
} public HttpServletRequest getRequest(){
return request;
} public HttpServletResponse getResponse(){
return response;
}
}在的Action类:
public class LoginAction extends ActionBase {
com.book.util.Hibernate hbm=new com.book.util.Hibernate();
/** public ActionForward execute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)throws HibernateException,IOException {
public ActionForward performLogin(ActionConfig cfg) throws
HibernateException {
String target="suss";
System.out.println(target);
ActionErrors errors = new ActionErrors();
LoginForm loginForm = (LoginForm)cfg.getForm();
String username=loginForm.getUsername();
String psw=loginForm.getPsw();
if(!hbm.isLogin(username,psw)){
target="fail";
errors.add("loginError",new ActionError("error.logerror"));
saveErrors(cfg.getRequest(),errors);
}
else{
HttpSession session = cfg.getRequest().getSession();
session.setAttribute("username", username); }
return cfg.getMapping().findForward(target); }当输入...?method=performLogin 老是报错
javax.servlet.ServletException: struts.Action.RoleAction.performSyslist(struts.ActionConfig)
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.NoSuchMethodException: struts.Action.RoleAction.performSyslist(struts.ActionConfig)
java.lang.Class.getMethod(Class.java:1581)
struts.ActionBase.execute(ActionBase.java:39)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
解决方案 »
- java类 自己调用自己无视private 这是为啥。 谁来解答一下
- Java基础题
- 这个程序里面p.x,p.y以及e.getX(),e.getY()的值都是double类型,API文档里Point(int x ,int y)。。。
- Java如何实现委托(delegate)?
- 怎样获取一个网页中的文字内容?
- 看看有错吗?
- 对一道完整例题的不完全注释,大家帮忙补充一下
- 在线等!如何知道runtime.exec(command)是否运行成功?
- JBuilder界面插件1.3.2,####最新####(20030627)
- 在java裡怎麼從一個文件裡一個一個的讀出字符(不知道文件裡有多少個字符)?
- 一个类含有多个jdbc操作的问题?
- Vector 类稳定性如何呢?
其他地方的问题吧