Java Reference
In-Depth Information
Output from the servlet:
Fig. 8.6 Result of a simple calculation sent back by servlet AdderServlet
8.8
Sessions
One fundamental restriction of HTTP is that it is a stateless protocol. That is to say,
each request and each response is a self-contained and independent transaction.
However, different parts of a Web site often need to know about data gathered in
other parts. For example, the contents of a customer's electronic cart on an
e-commerce shopping site need to be updated as the customer visits various pages
and selects purchases. To cater for this and a great number of other applications,
servlets implement the concept of a session . A session is a container where data
about a client's activities may be stored and accessed by any of the servlets that have
access to the session object. The session expires automatically after a prescribed
timeout period (30 min for Tomcat) has elapsed or may be invalidated explicitly by
the servlet (by execution of method invalidate ).
A session object is created by means of the getSession method of class
HttpServletRequest . This method is overloaded:
￿
HttpSession getSession()
￿
HttpSession getSession(boolean create)
Search WWH ::




Custom Search