-1

In the following snippet,uSession.isNewalways returns false. Why is that ? I create a new session but the corresponding method returns false.

HttpSession uSession = request.getSession();
    if(uSession.isNew()) {System.out.println("Inside if statement---------");
        uSession.setAttribute("username", username);
        uSession.setMaxInactiveInterval(3600);
        RequestDispatcher dispatcher = request.getRequestDispatcher("User.jsp");
        dispatcher.forward(request, response);
    }

I have even tried after deleting all the localhost cookies from the browser.

saplingPro
  • 20,769
  • 53
  • 137
  • 195

1 Answers1

0

Jsp automatically creates a session. I don't know why it creates. But it does. So your jsp automatically creates a session and that's why isNew() returns false all the time. The solution is to set the session to false in the JSP Page Directive. i.e., Use <%@ page session="false"%

Nishit
  • 1,276
  • 2
  • 11
  • 25