In my project I have a page which contains email and password field. my requirement is,after filling username and password fields,when I press submit,It will check username and password fields in database table..and if it match then it will go to the profile page.
so,I have done this:
mycontroller class is:
@RequestMapping(value = "/signin", method = RequestMethod.POST)
public String dologin(@ModelAttribute("student") Student student,HttpServletRequest request,
HttpServletResponse response,BindingResult result) {
try{
studentService.LoginStudent(student.getEmail(), student.getPassword());
if (result.hasErrors()) {
return "signin";
}
}
catch(ConstraintViolationException e){
}
return "profile";
}
my StudentServiceimpl.java is:
public Student LoginStudent(String email, String password) {
Student student = new Student(email,password);
studentDao.LoginStudent(student);
return student;
}
and StudentDao.java is:
public void LoginStudent(Student student) {
String hql = "select student_id from student where email = :email and password = :password";
sessionFactory.getCurrentSession().createSQLQuery(hql)
.setParameter("email", student.getEmail())
.setParameter("password", student.getPassword());
}
now,the problem is If I put any email id and any password it is directly going to the profile page.if the fields are blank then it is also going to the profile page.why it is not checking the fields?