STATE AND SESSIONS
This document describes a way to create stateful sessions with HTTP requests and responses. Currently, HTTP servers respond to each client request without relating that request to previous or subsequent requests; the technique allows clients and servers that wish to exchange state information to place HTTP requests and responses within a larger context, which we term a “session”. This context might be used to create, for example, a “shopping cart”, in which user selections can be aggregated before purchase, or a magazine browsing system, in which a user’s previous reading affects which offerings are presented.
There are, of course, many different potential contexts and thus many different potential types of session. The designers’ paradigm for sessions created by the exchange of cookies has these key attributes:
1. Each session has a beginning and an end.
2. Each session is relatively short-lived.
3. Either the user agent or the origin server may terminate a session.
4. The session is implicit in the exchange of state information.
Within a web-based application, JavaBeans can be stored in (and accessed from) a number of different collections of “attributes”. Each collection has different rules for the lifetime of that collection, and the visibility of the beans stored there. Together, the rules defining lifetime and visibility are called the scope of those beans. The JavaServer Pages (JSP) Specification defines scope choices using the following terms (with the equivalent servlet API concept defined in parentheses):
- page – Beans that are visible within a single JSP page, for the lifetime of the current request. (Local variables of the
- request – Beans that are visible within a single JSP page, as well as to any page or servlet that is included in this page, or forwarded to by this page. (Request attributes)
- session – Beans that are visible to all JSP pages and servlets that participate in a particular user session, across one or more requests. (Session attributes)
- application – Beans that are visible to all JSP pages and servlets that are part of a web application. (Servlet context attributes)
|作者：郎云鹏（dev2dev ID: hippiewolf）|