Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
212
Chapter 9 Session Tracking
Listing 9.2 CatalogPage.java (continued)
* To see the HTML that results from this method, do
* "View Source" on KidsBooksPage or TechBooksPage, two
* concrete classes that extend this abstract class.
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
if (items == null) {
response.sendError(response.SC_NOT_FOUND,
"Missing Items.");
return;
}
PrintWriter out = response.getWriter();
out.println(ServletUtilities.headWithTitle(title) +
"\n" +
"" + title + "
");
Item item;
for(int i=0; i
out.println("
");
item = items[i];
// Show error message if subclass lists item ID
// that's not in the catalog.
if (item == null) {
out.println("" +
"Unknown item ID " + itemIDs[i] +
"");
} else {
out.println();
String formURL =
"/servlet/coreservlets.OrderPage";
// Pass URLs that reference own site through encodeURL.
formURL = response.encodeURL(formURL);
out.println
("
"
" VALUE=\"" + item.getItemID() + "\">\n" +
"" + item.getShortDescription() +
" ($" + item.getCost() + ")\n" +
item.getLongDescription() + "\n" +
"\n
\n" +
"
"VALUE=\"Add to Shopping Cart\">\n" +
"\n\n");
}
}
out.println("
\n