Integrating the Shopping Cart
Now that we have a shopping cart bean, let's create a JSP that makes use of the cart. The JSP that we have created to do this is in Listing 13.2.
Code Listing 13.2. AddToShoppingCart.jsp
<%@ page errorPage="errorpage.jsp" %> <!-- Instantiate the ShoppingCart bean with an id of "cart" --> <jsp:useBean id="cart" scope="session" class="ShoppingCart" /> <html> <head> <title>DVD Catalog</title> </head> <body> <!-- If there is a new item on the request add it to the cart --> <% String id = request.getParameter("id"); if ( id != null ) { String desc = request.getParameter("desc"); Float price = new Float(request.getParameter("price")); cart.addItem(id, desc, price.floatValue(), 1); } %> <!-- Print the current quantity ... |
Get Pure Java Server Pages™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.