[ Team LiB ] Previous Section Next Section

Summary

Saving information between requests is extremely useful. You can personalize content or simply maintain the state of an application by being able to associate related transactions to a session. You can persist information by handing it back and forth using forms and hidden variables. However, it can be difficult to develop complex applications this way. JSPs and servlets make using sessions practi cally effortless. In JSPs, information that pertains to a session can be stored in the implicit session object. If you're using servlets, you can obtain an HttpSession through the HttpServletRequest object. Objects can implement interfaces such as HttpSessionBindingListener so that they can know when they are added to or removed from a session, or when a session is created or destroyed.

Although sessions usually use cookies to save a session key on the client, it's possible to still use sessions even if a client does not permit cookies. In this case, it's necessary to encode URLs so that the session key becomes a part of the URL. The JSP's implicit request object provides the encodeURL method to do this. Besides storing data on a per-client basis, you can also store data at an application scope.

    [ Team LiB ] Previous Section Next Section