Implementing the Shopping Cart

With your products on display, you can start actually allowing people to buy them. To do this, you're going to need to implement a shopping cart. If you want, you can refer back to the design of the shopping cart in Chapter 4, “The Sample Application Functional Requirements Document.”

A cart is essentially a container that you can put products into, with a few quirks. For example, putting a second copy of an item into a cart shouldn't make two entries; it should make a single item with a quantity of 2.

The cart has session persistence, like the customer. Unlike the customer object however, it doesn't get its contents from a database lookup. Eventually, when you get to filling and spilling content in Chapter 11

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL 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.