As many applications require requests coming from the same client to be associated, web applications have the responsibility to maintain this state in a special object called a session. Fortunately, Java servlets fully support sessions.
Within a servlet, a session of class HttpSession is obtained by calling the getSession() method of the HTTP request. A session object can then be manipulated with getAttribute()/setAttribute()/removeAttribute().
After some time, a session expires. To control the lifetime of a session, the following methods are used: setMaxInactiveInterval() and invalidate().
Implementing a shopping cart
Enhance the web application developed previously so that users can add specific songs to a shopping cart. Multiple users browsing from different computers should be able to have their distinct shopping carts. Each user should be able to clear his own cart at any time.
Leave a Reply