Guidelines, Patterns, and code for end-to-end Java applications.
A session is a sequence of service requests by a single user using a single client to access a server. The information maintained in the session across requests is called session state. Session state may include both information visible to the user (shopping cart contents, for example) and invisible application control information (such as user preferences).
HttpSession .HttpSession
At least three mechanisms can store session state in the client tier of a J2EE web application:
<INPUT TYPE="HIDDEN" ... >. These values are included in subsequent HTTP requests from the client, and used by the server as the session state. This mechanism can be encapsulated in a JSP tag to make the programming easier. The Java Pet Store sample application contains a sample implementation of such a tag, called ClientStateTag.Storing session state in the client tier allows servers to be stateless, which provides the following advantages over servers that maintain state:
HttpSession
We do not recommend storing session state directly on the client using cookies. See our recommendations for how to store session state. This section describes how to store session state directly on the client for those who choose to ignore these guidelines.
HttpServletResponseHttpServletRequest HttpServlet .service()
addCookie() method in class HttpServletResponse . Multiple cookies may be set for the same request, and a single cookie name may have multiple values.getCookies() method of class HttpServletRequest javax.servlet.http supports session management (via class HttpSession ), package javax.servlet has no such support.We do not recommend storing session state directly on the client using URL rewriting. See our recommendations for how to store session state. This section describes how to store session state directly on the client for those who choose to ignore these guidelines.
HttpServletResponse .encodeURL()encodeURL()