Java Reference
In-Depth Information
L ISTING 20.1
Continued
System.err.println(“Could not get a reference to Pool!”);
}
}
}
The only changes from the ConnectionPoolServlet found in Chapter 7 are the name of the
servlet, changing the URL to point to the catalog data source, and setting the number of con-
nections to two. Make sure you also add the following code snippet to the catalog's web.xml
file:
<servlet>
<servlet-name>CatalogConnectionPool</servlet-name>
<servlet-class>CatalogConnectionPool</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
This snippet preloads the CatalogConnectionPool when the Tomcat engine starts up.
Shopping Cart
The only real object that you will create for this case study is a simple shopping cart that will
hold the items the user has selected. The shopping cart will be represented by the
ShoppingCart class. Each user will get an instance of the ShoppingCart stored in their unique
session. The source code for the ShoppingCart object is in Listing 20.2.
L ISTING 20.2
ShoppingCart.java
import java.lang.String;
import java.lang.Integer;
import java.lang.Float;
import java.util.Hashtable;
import java.util.Enumeration;
public class ShoppingCart {
protected Hashtable items = new Hashtable();
public ShoppingCart() {
20
}
/**
Add a new item to the shopping cart.
*
attributes
itemId - the unique key associated with the item
 
Search WWH ::




Custom Search