Chapter 6. Session Management: Conversational state

image with no caption

Web servers have no short-term memory. As soon as they send you a response, they forget who you are. The next time you make a request, they don’t recognize you. In other words, they don’t remember what you’ve requested in the past, and they don’t remember what they’ve sent you in response. Nothing. Sometimes that’s fine. But sometimes you need to keep conversational state with the client across multiple requests. A shopping cart wouldn’t work if the client had to make all his choices and then checkout in a single request. You’ll find a surprisingly simple solution in the Servlet API.

OBJECTIVES

Session Management

4.1

Write servlet code to store objects into a session object and retrieve objects from a session object.

4.2

Given a scenario describe the APIs used to access the session object, explain when the session object was created, and describe the mechanisms used to destroy the session object, and when it was destroyed.

4.3

Using session listeners, write code to respond to an event when an object is added to a session, and write code to respond to an event when a session object migrates from one VM to another.

4.4

Given a scenario, describe which session management mechanism the Web container could employ, how cookies might be used to manage sessions, how URL rewriting might be used to manage sessions, and write servlet code to perform ...

Get Head First Servlets and JSP, 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.