A Server-Side Example Using the MVC

In this section, we create an MVC implementation using the Shopping Cart example we used in Chapter 13, "JSP and a Shopping Cart."

We will be using the following files from Chapter 13:

  • ShoppingCart.java

  • AddToShoppingCart.jsp

  • ShoppingCart.jsp

The first thing we are going to do is to remove scriptlet code used to add an item to the ShoppingCart from the AddToShoppingCart.jsp we used in Chapter 13. We will also need to change the action attribute of the form we used to point to our controller servlet instead of the JSP. You should notice how little scriptlet code is contained in our new JSP. Listing 16.1 contains the source for our changes. The new file is called AddToShoppingCartMVC.jsp.

Code Listing 16.1. AddToShoppingCartMVC.jsp ...

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.