How Sessions Work

Now that you see that servlets and Java Server Pages can support sessions, you can take a step back and look at how the sessions work. When the servlet engine creates a session, it sends a session identifier (also referred to as a session key earlier in this chapter) back to the browser in the form of a cookie. Again, the cookie is just a piece of information that the browser sends back to the server whenever it asks the server for a page.

Usually, for a session, the cookie disappears when the Web browser is shut down.

A browser can, however, save cookies to disk, so that when the browser starts up again it still knows about the cookies it had when it was shut down. Because sessions are typically short-lived, and because shutting ...

Get Special Edition Using Java™ 2 Enterprise 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.