问题描述
- 编译servlet类时总提示找不到XXX方法,求帮助可愁死我了
-
servlet类的代码如下
package org.wyd.mvcdemo.servlet;import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.wyd.mvcdemo.factory.DAOFactory;
import org.wyd.mvcdemo.vo.User;
public class LoginServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException{
String path = "login.jsp";
String userid = req.getParameter("userid");//接受userid内容
String userpass = req.getParameter("userpass");//接受userpass内容
Listinfo = new ArrayList();//保存所有返回信息
if(userid == null||"".equals(userid)){
info.add("用户名不能为空"); //增加错误信息
}
if(userpass == null||"".equals(userpass)){
info.add("密码不能为空"); //增加错误信息
}
if(info.size() == 0){//用户名密码通过验证不为空
User user = new User();//实例化vo
user.setUserid(userid);//设置userid
user.setPassword(userpass);//设置userpass
try{
if(DAOFactory.getIUserDAOInstance().findLogin(user)){//验证通过
info.add("用户登录成功,欢迎"+user.getName()+"光临!");
}else{
info.add("用户登录失败,错误的用户名或密码");
}
}catch(Exception e){
e.printStackTrace();
}
}
req.setAttribute("info",info);//保存错误信息
req.getRequestDispatcher(path).forward(req,resp);//跳转
}
public void doPost(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException{
this.doGet(req,resp);
}
}
解决方案
if(DAOFactory.getIUserDAOInstance().findLogin(user));
你这个DAOFactory是个静态类吗?
还是你的getIUserDAOInstance()是个静态方法;
还是你多添加了一个I;
如果回答对您有帮助,请采纳