To create a session on the server just blindly follow the following code, nothing simple than this ;)
HttpSession ses=request.getSession();
the code above creates a new session if none already exists.However if there is already a session then it returns the existing session and does not create a new one.
now there is one more expression which does exactly the same.
HttpSession ses=request.getSession(true);
however, if you are interested in only getting the existing session and do not want to create a new one,then use the code below instead.
HttpSession ses=request.getSession(false);
this will return the session if there exists one,but it will not create a new one and will return null if there is none.
HttpSession ses=request.getSession();
the code above creates a new session if none already exists.However if there is already a session then it returns the existing session and does not create a new one.
now there is one more expression which does exactly the same.
HttpSession ses=request.getSession(true);
however, if you are interested in only getting the existing session and do not want to create a new one,then use the code below instead.
HttpSession ses=request.getSession(false);
this will return the session if there exists one,but it will not create a new one and will return null if there is none.
No comments:
Post a Comment