I've read How to implement “Stay Logged In” when user login in to the web application. I have two questions,mainly about HttpServletRequest#login().
Question1: If user returned by userDAO.find() is not null, does it mean
the username and password is correct and the user should be logged in?
Question2: What does HttpServletRequest#login do as for validating user?
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String username = request.getParameter("username");
String password = request.getParameter("password");
User user = userDAO.find(username, password);
if (user != null) { // If true , does it prove the username and password is correct?
try {
/* Why call request.login() here? I think the client has been
* validated if user!=null. What's the use of this line?
*/
request.login(username, password);
System.out.println.("successfully log in");
} catch (Exception e) {
e.printStackTrace();
}
}