Skip to Main Content
Java Servlet Programming
book

Java Servlet Programming

by Jason Hunter
November 1998
Intermediate to advanced content levelIntermediate to advanced
526 pages
14h 38m
English
O'Reilly Media, Inc.
Content preview from Java Servlet Programming

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.

Interface Declaration ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Servlet Programming, 2nd Edition

Java Servlet Programming, 2nd Edition

Jason Hunter, William Crawford

Publisher Resources

ISBN: 156592391XSupplemental ContentCatalog PageErrata