Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
9.4 An On Line Store Using a Shopping Cart and Session Tracking
211
Listing 9.2 CatalogPage.java (continued)
* is done by putting calls to setItems and setTitle
* in init.
*/
public abstract class CatalogPage extends HttpServlet {
private Item[] items;
private String[] itemIDs;
private String title;
/** Given an array of item IDs, look them up in the
* Catalog and put their corresponding Item entry
* into the items array. The Item contains a short
* description, a long description, and a price,
* using the item ID as the unique key.
*
* Servlets that extend CatalogPage must call
* this method (usually from init) before the servlet
* is accessed.
*/
protected void setItems(String[] itemIDs) {
this.itemIDs = itemIDs;
items = new Item[itemIDs.length];
for(int i=0; i
items[i] = Catalog.getItem(itemIDs[i]);
}
}
/** Sets the page title, which is displayed in
* an H1 heading in resultant page.
*
* Servlets that extend CatalogPage must call
* this method (usually from init) before the servlet
* is accessed.
*/
protected void setTitle(String title) {
this.title = title;
}
/** First display title, then, for each catalog item,
* put its short description in a level two (H2) heading
* with the price in parentheses and long description
* below. Below each entry, put an order button
* that submits info to the OrderPage servlet for
* the associated catalog entry.
*
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved