[ Team LiB ] Previous Section Next Section

Workshop

The Workshop is designed to help you review what you have learned, and help you to further increase your understanding of the material covered in this hour.

Quiz

1:

Why did we use a servlet instead of a JSP to add or remove items from the shopping cart?

2:

In this example, the information about items was embedded in the URL used to add them to the shopping cart. How can you simplify the URL?

3:

If you attempted to run the cookie example given in this hour, why didn't it work? (Hint: The code is okay.)


Answers

A1:

By nature, JSPs are oriented to presentation. After all, the majority of their content is markup. On the other hand, servlets are made up of code. Many designers choose to try and place most of the view in JSPs and to use servlets to implement functions involving the model. Adding or removing items from the shopping cart is a function that affects the model.

A2:

You can give the item an identifier that can be used to lookup information that is needed in other stages of the order. As mentioned in the text, the full description of the item can be stored in the application or session, or in a database.

A3:

Browsers will only accept cookies for the domain of the resource they requested. This prevents a server in the imacrook.com domain from changing a cookie that belongs to your online banking application. To get the example to work for you, change the cookie's domain.


Activities

  1. Modify the shopping cart example to accept an order quantity from the user. Start with ShowProductCatalog2.jsp and use a form.

  2. Change ShoppingCart.java so that it's notified when a session is terminated.

  3. Modify the shopping cart example to use a cookie to store items that are in the shopping cart. Retrieve the cookie when the user first visits the application and repopulate the cart.

    [ Team LiB ] Previous Section Next Section