Java Reference
In-Depth Information
The Contents of Shopping Cart screen.
To understand how this first part works, you need to examine the doPost() method. This is the
method that services the POST request sent by your HTML document.
The first thing the doPost() method does is get the list of submitted movies from the request.
It then tries to get a reference to the HttpSession object stored in the HttpServletRequest .
This is done by calling the HttpServletRequest.getSession() method. The code snippet that
performs this is listed in the following:
// Get a handle to the HttpSession Object
// if there is no session create one
HttpSession session = request.getSession(true);
The getSession() method takes one parameter. This parameter is a Boolean value that, if
true , tells the method to create an HttpSession if one doesn't exist.
When you have a reference to the HttpSession object, you can add your movie list to it. You
do this by calling the HttpSession.setAttribute() method, passing it the name “Movies”
and the object to be bound to it: movies . The movie list is now stored in the client's session.
The last thing you do in the doPost() method is redisplay the list of selected movies and ask
the user to click Proceed to Checkout.
Search WWH ::

Custom Search