Name

HttpSession

Synopsis

Interface Name: javax.servlet.http.HttpSession

Superinterface: None

Immediate Subinterfaces: None

Implemented By: None

Availability: Servlet API 2.0 and later

Description

The HttpSession interface provides a mechanism for holding temporary information about 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 client requests.

A servlet obtains an HttpSession object from the getSession( ) method of HttpServletRequest. Session behavior, such as the amount of idle time before a session is destroyed, can be configured programmatically and via the web application deployment descriptor.

For sessions inside a nondistributed web application, any object may be bound to the session. Objects that implement java.io.Serializable may be written to disk to save memory and to persist between server restarts.

For sessions inside a distributed web application, objects placed into the session must implement java.io.Serializable. The server may throw an IllegalArgumentException when this requirement is not met. Servers use session affinity to efficiently manage sessions in a distributed environment where there are multiple backend servers. ...

Get Java Servlet Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.