Name
HttpSession
Synopsis
Interface Name: javax.servlet.http.HttpSession
Superinterface: None
Immediate Subinterfaces: None
Implemented By: None
Availability: New as of the Servlet API 2.0; found in JSDK 2.0, JWS 1.1
Description
The HttpSession interface provides a mechanism for
identifying return visitors to a web site. For a detailed
introduction to session tracking, see Chapter 7.
The HttpSession interface itself allows servlets
to view and manipulate session-specific information, such as creation
time and the unique session identifier. It also includes methods to
bind objects to the session for later retrieval, allowing
“shopping cart” and other applications to hold onto data
between connections without resorting to databases or other
extra-servlet resources.
A servlet obtains an HttpSession object from the
getSession() method of
HttpServletRequest. Specific session behavior,
such as the amount of idle time before a session is destroyed,
depends on the server.
While any object can be bound to a session, lots of high-traffic
servlets binding large objects to their sessions will impose a heavy
resource burden on the server. With most implementations, this can be
alleviated by binding only objects that implement the
java.io.Serializable interface (this includes all
of the data type objects in the core Java API). Some servers have the
ability to write Serializable objects to disk to
save memory. Unserializable objects, such as
java.sql.Connection, must be retained in memory.