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.
.
Thanks for the post.
ReplyDeleteGreat sir.
ReplyDelete