• HttpSession helps to store the full session object for a specific client
  • HttpSession provides some methods which help to store attributes and remove attributes from a session

The following code shows how to create a new HttpSession object

  • This code creates a session object with a name of “session" and an attribute user with value name
  • The session can be invalidated with the void invalidate() method

List of the HttpSession methods to help manage session

  • long getCreationTime(): It will return session creation time in milliseconds
  • String getId(): It will return the unique identifier of the session
  • long getLastAccessedTime(): Returns the time of the last request for the session
  • int getMaxInactiveInterval(): Returns the session active time
  • void invalidate(): This method will destroy the session
  • boolean isNew(): Returns value true or false of session creation
  • void setMaxInactiveInterval(int interval): Active time of session in container