在userdao类下,写个函数,用来判断登录用户的。
- Java code
public boolean check(String name,String password) { SessionFactory sessionFactory = HibernateSessionFactory .getSessionFactory(); Session session = sessionFactory.openSession(); //Transaction transaction=session.beginTransaction(); String hql1 = "from Hr_User hrUser where hrUser.username=? and hrUser.userpassword=?"; Query query = session.createQuery(hql1).setString(0, name).setString(1, password); List<Hr_User> list = query.list(); if (list.size() > 0) { session.close(); return true; } else { session.close(); return false; } }
然后再Hr_Useraction类里写个login函数,在login.jsp里面,登录名的name=hrUser.username,密码name=hrUser.userpassword
Hr_Useraction类里
private String name;
private String password;
private Hr_UserDAO hrUserDAO = new Hr_UserDAO();
- Java code
public String hr_userLogin() { bool=hrUserDAO.check(name,password); if(bool==true){ return SUCCESS; } else { return INPUT; } }
问题:在登录的页面跳转不过去,请问这代码哪有问题?
------解决方案--------------------
有报异常吗?