HttpServletRequest
interface provides below methods to create a session.
getSession()
getSession(boolean
create)
HttpSession
getSession()
If
the request includes a session id cookie, then it finds the session
matching with id, if there is no session matching with the id then it
create one. If there is no session id in the request, then it creates
a session.
HttpSession
getSession(boolean create)
Reurns
the current HttpSession associated with this request or, if there is
no current session and create is true, returns a new session. If
create is false and the request has no valid HttpSession, this method
returns null.
The
getSession() method should be called before anything is written to
the response stream. Once the session is created, you can add data to
your session using setAttribute method, and retrieve using
getAttribute and remove using removeAttribute method.
No comments:
Post a Comment