
为什么我的action不能调用dao
我的action代码:publicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServlet...
我的action代码:public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String username=request.getParameter("username");
String password=request.getParameter("password");
System.out.println(password);
Admin admin=new Admin();
admin.setUsername(username);
admin.setPassword(password);
System.out.println("dfcdsgfhj46546757");
if(AdminDAO.login(admin)){
HttpSession session=request.getSession();
session.setAttribute("admin", admin);
System.out.println("dfcdsg");
return mapping.findForward("success");
}
return mapping.findForward("fail");
}
我的dao代码:public class AdminDAO {
public static boolean login(Admin admin) throws SQLException {
Connection con=ConnectionManager.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select id,password from admin where name=?";
try{
System.out.println("dfsgvfd");
ps=con.prepareStatement(sql);
ps.setString(1,admin.getUsername());
rs=ps.executeQuery();
if(rs.next()){
String password=rs.getString(2);
if(admin.equals(password)){
admin.setId(rs.getInt(1));
return true;
}
}
}finally{
ConnectionManager.closeConnection(con);
}
return false;
}
}
我感觉没错啊,可是为什么在action中从if语句开始就不能继续执行了了,在后台还没有错误报告。
因为真的想好好学习Java,所以请教各位了!! 展开
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String username=request.getParameter("username");
String password=request.getParameter("password");
System.out.println(password);
Admin admin=new Admin();
admin.setUsername(username);
admin.setPassword(password);
System.out.println("dfcdsgfhj46546757");
if(AdminDAO.login(admin)){
HttpSession session=request.getSession();
session.setAttribute("admin", admin);
System.out.println("dfcdsg");
return mapping.findForward("success");
}
return mapping.findForward("fail");
}
我的dao代码:public class AdminDAO {
public static boolean login(Admin admin) throws SQLException {
Connection con=ConnectionManager.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select id,password from admin where name=?";
try{
System.out.println("dfsgvfd");
ps=con.prepareStatement(sql);
ps.setString(1,admin.getUsername());
rs=ps.executeQuery();
if(rs.next()){
String password=rs.getString(2);
if(admin.equals(password)){
admin.setId(rs.getInt(1));
return true;
}
}
}finally{
ConnectionManager.closeConnection(con);
}
return false;
}
}
我感觉没错啊,可是为什么在action中从if语句开始就不能继续执行了了,在后台还没有错误报告。
因为真的想好好学习Java,所以请教各位了!! 展开
3个回答
展开全部
你的AdminDAO写错了吧
我没有把代码COPY到我的工程里
我只是这么看的
觉得你这句话
if(admin.equals(password)){
admin.setId(rs.getInt(1));
return true;
}
括号里的东西就有问题.
应该是admim.getPassword.equals(password)吧?
我就看到这 感觉有问题.
我没有把代码COPY到我的工程里
我只是这么看的
觉得你这句话
if(admin.equals(password)){
admin.setId(rs.getInt(1));
return true;
}
括号里的东西就有问题.
应该是admim.getPassword.equals(password)吧?
我就看到这 感觉有问题.
展开全部
if(admin.equals(password)){
admin.setId(rs.getInt(1));
return true;
}
有错。你这里admin是传入的一个对象吧。应该用这个对象的password属性和password进行比对啊,你这是对象和string比了
admin.setId(rs.getInt(1));
return true;
}
有错。你这里admin是传入的一个对象吧。应该用这个对象的password属性和password进行比对啊,你这是对象和string比了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(admin.equals(password)){...}
这里
if(admin.getPassword.equals(password)){...}
这里
if(admin.getPassword.equals(password)){...}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询