O'Reilly logo

Java Servlet Programming, 2nd Edition by William Crawford, Jason Hunter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required