What Is The Difference Between getSession (true) and getSession (false) In Java?

Java_LOGO

As we know, HTTP is a stateless protocol  so series of interactions are difficult to maintain between client and server. That’s why we  use HttpSession object to maintain these series of interactions between client and server.
Here is the syntax for getting the session object without any parameter.
HttpSession session=request.getSession();

above statement  will  returns the current session associated with the request and if it does not exist, a new session will be created.
HttpSession session = request.getSession(true);

above statement  will  returns the current session associated with the request and  if session doesn't exit, a new one will be created.
So above two statements have  no difference.
HttpSession session =request.getSession(false);

above statement  will  returns the current session if session exists and if there's no valid session, a new session  will not be created,  it  will return null.
.
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

2 comments: