I made sure I closed all the bracket, why do i still get the error.
on line 360, 424, 425 and 607
Please help
/*
* ShopCartServlet HW3.java
*
* Created on November 19, 2007, 5:42 PM
*/
package ITIS4166HW5;
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
import java.text.*;
import javax.servlet.* ;
import javax.servlet.h ttp.*;
/**
*
* @author Administrator
* @version
*/
public class ShopCartServlet HW3 extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
private String pageTop01;
private String pageTop02;
private String pageTop03;
private String pageTop04;
private String pageTable01Top;
private String pageTable01Bott om;
private String pageBottom;
private String pageItemEmpty;
private String confirmTable01B ottom;
private String confirmTableTop ;
private String confirmItemEmpt y;
private Hashtable pageItemList = new Hashtable();
private Hashtable confirmItemList = new Hashtable();
private double runningTotal;
private ShopCartDataHW3 cartData;
private InvTrackerHW3 invTracker;
private Hashtable pastOrders;
public void init() throws ServletExceptio n {
PageTop01 = "<html>"
+ "<head>"
+ "<title>Blu e Ridge Supply Shopping Cart </title>"
+ "</head>"
+ "<style type=\"text/css\">"
+ "body {font-family: arial}"
+ "h1 {color: navy}"
+ "h2 {color: navy}"
+ "h3 {color: white}"
+ "h4 {color: white"
+ "h5 {color: white}"
+ "h6 {color: navy}"
+ "p {color: navy}"
+ "</style>"
+ "<body>";
pageTop02 = "<table border=\"0\" width=\"100%\" cellpadding=\"0 \">"
+ "<tr><td width=\"25%\" valign=\"top\"> "
+ "Shopper: ";
pageTop03 = "<br>"
+ "<a href=\"RegLogin ServletHW3\"> [Log Out]</a>"
+ " "
+ "<a href=\"CatServl etHW3\">[Continue Shopping]</a></td>"
+ "<td width=\"50%\" valign=\"bottom \" align=\"center\ "><h1>"
+ "Blue Ridge Supply - Shopping Cart"
+ "</h1>"
+ "<td width=\"25%\" valign=\"top\" align=\"right\" >"
+ "Shopping Cart contains ";
pageTop04 = " items </em> "
+ "</td></tr></table><hr>";
pageTable01Top = "<center><h 3>"
+ "Please review sections:"
+ "</h3><table border=\"1\" cellpadding=\"1 0\" align=\"center\ " valign=\"middle \" bgcolor=\"navy\ ">"
+ "<tr><th><h4><b r>"
+ "Quantity"
+ "</h4></th<th><h4>"
+ "Item"
+ "</h4></th><th><h4>"
+ "Unit Price"
+ "</h4></th></th><h4>"
+ "Total Price"
+ "</h4></th></tr>";
pageBottom = "</body></html>";
}
protected void processRequest( HttpServletRequ est request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
HttpSession session = request.getSess ion();
if (session.isNew( ) || session == null) {
sessionError( request, response);
}
String userID;
if (session.getAtt ribute("userID" ) != null) {
userID = (String)session .getAttribute(" userID");
} else {
sessionError( request, response);
userID = "";
}
Integer cartCount;
if (session.getAtt ribute("cartCou nt") != null)
{
cartCount = (Integer)sessio n.getAttribute( "cartCount" );
} else {
sessionError( request, response);
cartCount = Integer.valueOf (0);
}
if (session.getAtt ribute("pastOrd ers") != null)
{
pastOrders = (Hashtable)
session.getAttr ibute("pastOrde rs");
} else {
sessionError( request, response);
pastOrders = new Hashtable();
}
if (session.getAtt ribute("invTrac ker") != null)
{
invTracker = (InvTrackerHW3)
session.getAttr ibute("invTrack er");
}
String shiptoname;
String streetaddress;
String city;
String state;
String zip;
String shipservice;
String cctype;
String ccname;
String ccnum;
String ccexpmonth;
String ccexpyear;
// Shipping information
Hashtable shipHash;
if ((session.getAt tribute("shippi ng") != null))
{
shipHash = ((Hashtable)ses sion.getAttribu te("shipping")) ;
} else {
shipHash = new Hashtable();
}
String [] shipping = new String[5];
if (shipHash.get(u serID) != null) {
shipping = (String[])shipHash.get(u serID);
shiptoname = shipping[0];
streetaddress = shipping[1];
city = shipping[2];
state = shipping[3];
zip = shipping[4];
} else {
shiptoname = "";
streetaddress = "";
city = "";
state = "";
zip = "";
}
/*
if ((session.getAt tribute("shipto name") != null)) {
shiptoname = filter((String) session.getAttr ibute("shiptona me"))
*/
// Credit information
if ((session.getAt tribute("shipse rvice") != null)) {
shipservice = filter((String) session.getAttr ibute("shipserv ice"));
} else {
shipservice = "";
}
if ((session.getAt tribute("ccname ") != null)) {
ccname = filter((String) session.getAttr ibute("ccname") );
} else {
ccname = "";
}
if ((session.getAt tribute("cctype ") != null)) {
cctype = filter((String) session.getAttr ibute("cctype") );
} else {
cctype = "";
}
if ((session.getAt tribute("ccnum" ) != null)) {
ccnum = filter((String) session.getAttr ibute("ccnum")) ;
} else {
ccnum = "";
}
if ((session.getAt tribute("ccexpm onth") != null)) {
ccexpmonth = filter((String) session.getAttr ibute("ccexpmon th"));
} else {
ccexpmonth = "";
}
if ((session.getAt tribute("ccexpy ear") != null)) {
ccexpyear = filter((String) session.getAttr ibute("ccexpyea r"));
} else {
ccexpyear = "";
}
if (session.getAtt ribute("cart") != null && session.getAttr ibute("cartKeys ") != null)
cartData = new ShopCartDataHW3 ((Hashtable) session.getAttr ibute("cart"), (Hashtable)
session.getAttr ibute("cartKeys "));
else {
cartData = new ShopCartDataHW3 (new Hashtable(), new Hashtable());
}
String itemToAdd;
itemToAdd = (findItemAttrib ute(request, response));
if ((itemToAdd != null) && (cartData.getIt emID(itemToAdd) == null)) {
cartData.update ItemID(itemToAd d, 1);
}
if (itemToAdd != null) {
int defaultValue = (cartData.getQt y(itemToAdd).in tValue());
int x = getIntParameter (request, itemToAdd, defaultValue);
if (x < 0) {
// do nothing
} else {
cartData.update ItemID(itemToAd d, x);
}
}
Hashtable cart = new Hashtable(cartD ata.getCart());
Hashtable cartKeys = new Hashtable (cartData.getCa rtKeys());
session.setAttr ibute("cart", cart);
session.setAttr ibute("cartKeys ", cartKeys);
Integer numberOfKeys = new Integer (cartKeys.size( ));
session.setAttr ibute("cartCoun t", numberOfKeys);
runningTotal = 0;
Enumeration keyValues = cartKeys.elemen ts();
while(keyValues .hasMoreElement s()) {
String key = (String) keyValues.nextE lement();
if (key != null) {
setCartPage(key , cartData);
setConfirmItemL ist(key, cartData);
}
}
if (numberOfKeys.i ntValue() == 0) {
setCartPage(nul l, cartData);
}
String shippingAndCred it = loadShippingAnd Credit(shiptona me, streetaddress, city, state, zip, shipservice, cctype, ccname, ccnum, ccexpmonth, ccexpyear);
if (numberOfKeys.i ntValue() == 0) {
session.setAttr ibute("confirm" , "");
} else {
setConfirm(sess ion, cartKeys, numberOfKeys);
}
showPage(reques t, response, userID, cartKeys, numberOfKeys, shippingAndCred it);
}
private void showPage(HttpSe rvletRequest request,
HttpServletResp onse response, String userId, Hashtable cartKeys, Integer numberOfKeys, String shippingAndCred it)
throws ServletExceptio n, IOException {
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
out.println(pag eTop01 + pageTop02 + userID + pageTop03 + numberOfKeys + pageTop04);
out.println(shi ppingAndCredit) ;
out.println(pag eTable01Top);
Enumeration keyValues = cartKeys.elemen ts();
while(keyValues .hasMoreElement s()) {
String key = (String)keyValu es.nextElement( );
if (key != null) {
out.println(pag eItemList.get(k ey));
}
}
if (numberOfKeys.i ntValue() == 0) {
out.println(pag eItemEmpty);
}
out.println(pag eTable01Bottom + pageBottom);
out.close();
}
private String findItemAttribu te(HttpServletR equest request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
Enumeration paramNames = request.getPara meterNames();
while(paramName s.hasMoreElemen ts()) {
String paramName = (String) paramNames.next Element();
CatalogHW3 item = new CatalogHW3();
if (item.getItem(p aramName) != null) {
return paramName;
}
}
return null;
}
private void setCartPage(Str ing key, ShopCartDataHW3 cartData) {
String pageItemFormat0 0 = "<form action=\"ShopCa rtServletHW3\" method=\"post\" ><tr bgcolor=\"white \"><td align=\"center\ ">"
+ "<input type=\text\" name=\"";
String pageItemFormat0 1 = "\" value=\"";
String pageItemFormat0 2 = "\" size=\"3\" align=\"right\" >"
+ "<input type=\"submit\" name=\"Update\" value=\"Update\ " />"
+ "<br>";
String pageItemFormat0 3 = "</td><td><img src=\"";
String pageItemFormat0 4 = "\" align=\"middle\ " width=\"48\" height=\"48\"> ";
String pageItemFormat0 5 = "</td><td align=\"right\" >";
String pageItemFormat0 6 = "</td><td align=\"right\" >";
String pageItemFormat0 7 = "</td></tr></form>";
DecimalFormat f = new DecimalFormat() ;
if (key != null) {
int qtyOnHand = invTracker.getQ tyOnHand(key);
int qtyAvailable = qtyOnHand - cartData.getQty (key).intValue( );
if (qtyAvailable < 0) {
cartData.update ItemID(key, invTracker.getQ tyOnHand(key));
qtyAvailable = 0;
}
double total = ((cartData.getQ ty(key).intValu e() * cartData.getCos t(key)));
pageItemList.pu t(key, pageItemFormat0 0
+ cartData.getIte mID(key)
+ pageItemFormat0 1
+ cartData.getQty (key)
+ pageItemFormat0 2
+ qtyAvaliable + " More Avaliable "
+ pageItemFormat0 3
+ cartData.getIma gePath(key)
+ pageItemFormat0 4
+ cartData.getDes cription(key)
+ pageItemFormat0 5
+ "$" + f.format(cartDa ta.getCost(key) )
+ pageItemFormat0 6
+ "$" + f.format(total)
+ pageItemFormat0 7);
runningTotal = total + runningTotal;
} else {
pageItemEmpty = "<tr bgcolor=\"white \"><td colspan=\"4\" align=\"center\ ">"
+ "Your Shopping Cart is empty ... Please buy something."
+ "</td></tr>";
runningTotal = 0;
}
pageTable01Bott om = "<tr><td colspan=\"4\" align=\"Right\" ><h4> Total Order: $ "
+ f.format(runnin gTotal)
+ "</h4></td></tr></table>";
}
}
private void setConfirmItemL ist(String key, ShopCartDataHW3 cartData) {
confirmTableTop = "<center><h 3>"
+ "Order Details"
+ "<table border=\"1\" cellpadding=\"1 0\" align=\"center\ " valign=\"middle \">"
+ "<tr><th><h4><b r>"
+ "Quantity"
+ "</h4></th<th><h4>"
+ "Item"
+ "</h4></th><th><h4>"
+ "Unit Price"
+ "</h4></th></th><h4>"
+ "Total Price"
+ "</h4></th></tr>";
String confirmItemForm at00 = "<tr bgcolor=\"white \"><td align=\"center\ ">";
String confirmItemForm at01 = "<td align=\"right\" >";
String confirmItemForm at02 = "</td><td>";
String confirmItemForm at03 = "<img src =\"";
String confirmItemForm at04 = "\" align=\"middle\ " width=\"48\" height=\"48\"> ";
String confirmItemForm at05 = "</td><td align=\"right\" >";
String confirmItemForm at06 = "</td><td align=\right\"> ";
String confirmItemForm at07 = "</td></tr>";
DecimalFormat f = new DecimalFormat() ;
if (key != null) {
double total = ((cartData.getQ ty(key).intValu e() * cartData.getCos t(key)));
confirmItemList .put(key,
confirmItemForm at01
+ cartData.getQty (key)
+ confirmItemForm at02
+ confirmItemForm at03
+ cartData.getIma gePath(key)
+ confirmItemForm at04
+ cartData.getDes cription(key)
+ confirmItemForm at05
+ "$" + f.format(cartDa ta.getCost(key) )
+ confirmItemForm at06
+ "$" + f.format(total)
+ confirmItemForm at07);
}
confirmTable01B ottom = "<tr><td colspan=\"4\" align=\"Right\" ><h4>TOTAL ORDER: $ "
+ f.format(runnin gTotal)
+ "</h4></td></tr></table>";
}
private void setConfirm(Http Session session,
Hashtable cartKeys, Integer numberOfKeys)
throws ServletExceptio n, IOException {
StringBuffer confirm = new StringBuffer(co nfirmTableTop);
Enumeration keyValues = cartKeys.elemen ts();
while(keyValues .hasMoreElement s()) {
String key = (String)keyValu es.nextElement( );
if (key != null) {
confirm.append( (String)
confirmItemList .get(key));
}
}
if (key != null) {
confirm.append( (String)
confirmItemList .get(key));
}
}
confirm.append( confirmTable01B ottom);
session.setAttr ibute("confirm" , confirm.toStrin g());
}
private String loadShippingAnd Credit(String shiptonmae, String streetaddress, String city, String state, String zip, String shipservice, String cctype, String ccname, String ccnum, String ccexpmonth, String ccexyear) {
String credit01;
String credit02;
String credit03;
String ship01;
String ship02;
String ship03;
String ship04;
String ship05;
String ship06;
credit01 = "<form action=\"PurchC onfServletHW3\" method=\"post\" >"
+ "<table border=\"1\" cellpadding=\"1 0\" bgcolor=\"navy\ " align\"center\" >";
ship01 = "<center><h 3>"
+ "Please provide your billing and shipping information: "
+ "<input type=\"submit\" name=\"Submit Order\" value=\"Submit Order\" />"
+ "</h3></hr>";
String
bill01 = "<tr><td bgcolor=\"white \">"
+ "Card Type:"
+ "<br>"
+ "<select name=\"cctype\" >"
+ "<option value=\"Visa\" selected=\"sele cted\"> Visa</option>"
+ "<option value=\"MasterC ard\" selected=\"sele cted\"> MasterCard</option>"
+ "<option value=\"America n Express\" selected=\"sele cted\">American Express</option>"
+ "</select><br>"
+ "Card Number:"
+ "<br>"
+ "<input type=\"text\" name=\"ccnum\" value=\"";
credit02 = "\"><br>"
+ "Cardholder Name:"
+ "<br>"
+ "<input type=\"text\" name=\"ccname\" value=\"";
credit03 = "\"><br>"
+ "Expiration Date:"
+ "<br>"
+ "<select name=\"ccexpmon th\">"
+ "<option value=\"Jan\">J an</option>"
+ "<option value=\"Feb\">F eb</option>"
+ "<option value=\"Mar\">M ar</option>"
+ "<option value=\"Apr\">A pr</option>"
+ "<option value=\"May\">M ay</option>"
+ "<option value=\"Jun\">J un</option>"
+ "<option value=\"Jul\">J ul</option>"
+ "<option value=\"Aug\">A ug</option>"
+ "<option value=\"Sep\">S ep</option>"
+ "<option value=\"Oct\">O ct</option>"
+ "<option value=\"Nov\">N ov</option>"
+ "<option value=\"Dec\">D ec</option>"
+ "</select>"
+ "</td>";
String
ship00 = "<td bgcolor=\"white \">"
+ "Ship To Name:"
+ "<br>"
+ "<input type=\"text\" name=\"shiptona me\" size=\"37\" value=\"";
ship02 = "\"<br>"
+ "Street Address:"
+ "<br>"
+ + "<input type=\"text\" name=\"streetad dress\" size=\"37\" value=\"";
ship03 = "\"<br>"
+ "City State Zip:"
+ "<br>"
+ "<input type=\"text\" name=\"city\" size=\"20\" value=\"";
ship04 = "\">"
+ "<input type=\"text\" name=\"state\" size=\"2\" value=\"";
ship05 = "\">"
+ "<input type=\"text\" name=\"zip\" size=\"5\" value=\"";
ship06 = "\"</td>";
String
ship00a = "<td bgcolor=\"white \">"
+ "<input type=\"radio\" checked=\"check ed\" name=\"shipserv ice\" value=\"UPS Ground\">UPS Ground"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipserv ice\" value=\"UPS 2nd Day Air\">UPS 2nd Day Air"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipserv ice\" value=\"FedEx Priority\">FedE x Priority"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipserv ice\" value=\"FedEx Ultra\">FedEx Ultra"
+ "</td>";
String
ship00c = "</tr>"
+ "</table></form>";
return credit01
+ ship01
+ bill01
+ ccnum
+ credit02
+ ccname
+ credit03
+ ship00
+ shiptoname
+ ship02
+ ship03
+ streetaddress
+ city
+ ship04
+ state
+ ship05
+ zip
+ ship06
+ ship00a
+ ship00c;
}
private void sessionError(Ht tpServletReques t request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
String sessionErrorFor m;
sessionErrorFor m = "<form action=\"RegLog inServletHW3\" method=\"post\" ><tr bgcolor=\"white \"> <td align=\"center\ ">"
+ "<h3 align=\"center\ ">Your request has not been processed - some isseues were found. <br> Please return to the Login page. </h3>"
+ "<input type=\"submit\" name=\"Go to Login\" value=\"Go to Login\" /></form>";
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
out.println(pag eTop01 + sessionErrorFor m);
out.close();
}
private String filter(String input) {
StringBuffer filter = new StringBuffer(in put.length());
char c;
for(int i=0; i<input.length( ); i++) {
c = input.charAt(i) ;
if (c == '<') {
filtered.append ("<");
} else if ( c == '>') {
filtered.append (">");
} else if ( c == '"') {
filtered.append (""");
} else if (c == '&') {
filtered.append ("&");
} else {
filtered.append (c);
}
}
return(filtered .toString());
}
private int getIntParameter (HttpSevletRequ est request,
String paramName,
int defaultValue) {
String paramString = request.getPara meter(paramName );
int paramValue;
try {
paraValue = Integer.parseIn t(paramString);
} catch (NumberFormatEx ception nfe) { // null or bad format
paramValue = defaultValue;
}
return(paramVal ue);
}
//<editor-fold defaultstate="c ollapsed" desc="HttpServl et methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code>method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServl etRequest request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
processRequest( request, response);
}
/** Handles the HTTP <code>POST</code>method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServ letRequest request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
processRequest( request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo( ) {
return "Short description";
}
// </editor-fold>
}
on line 360, 424, 425 and 607
Please help
/*
* ShopCartServlet HW3.java
*
* Created on November 19, 2007, 5:42 PM
*/
package ITIS4166HW5;
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
import java.text.*;
import javax.servlet.* ;
import javax.servlet.h ttp.*;
/**
*
* @author Administrator
* @version
*/
public class ShopCartServlet HW3 extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
private String pageTop01;
private String pageTop02;
private String pageTop03;
private String pageTop04;
private String pageTable01Top;
private String pageTable01Bott om;
private String pageBottom;
private String pageItemEmpty;
private String confirmTable01B ottom;
private String confirmTableTop ;
private String confirmItemEmpt y;
private Hashtable pageItemList = new Hashtable();
private Hashtable confirmItemList = new Hashtable();
private double runningTotal;
private ShopCartDataHW3 cartData;
private InvTrackerHW3 invTracker;
private Hashtable pastOrders;
public void init() throws ServletExceptio n {
PageTop01 = "<html>"
+ "<head>"
+ "<title>Blu e Ridge Supply Shopping Cart </title>"
+ "</head>"
+ "<style type=\"text/css\">"
+ "body {font-family: arial}"
+ "h1 {color: navy}"
+ "h2 {color: navy}"
+ "h3 {color: white}"
+ "h4 {color: white"
+ "h5 {color: white}"
+ "h6 {color: navy}"
+ "p {color: navy}"
+ "</style>"
+ "<body>";
pageTop02 = "<table border=\"0\" width=\"100%\" cellpadding=\"0 \">"
+ "<tr><td width=\"25%\" valign=\"top\"> "
+ "Shopper: ";
pageTop03 = "<br>"
+ "<a href=\"RegLogin ServletHW3\"> [Log Out]</a>"
+ " "
+ "<a href=\"CatServl etHW3\">[Continue Shopping]</a></td>"
+ "<td width=\"50%\" valign=\"bottom \" align=\"center\ "><h1>"
+ "Blue Ridge Supply - Shopping Cart"
+ "</h1>"
+ "<td width=\"25%\" valign=\"top\" align=\"right\" >"
+ "Shopping Cart contains ";
pageTop04 = " items </em> "
+ "</td></tr></table><hr>";
pageTable01Top = "<center><h 3>"
+ "Please review sections:"
+ "</h3><table border=\"1\" cellpadding=\"1 0\" align=\"center\ " valign=\"middle \" bgcolor=\"navy\ ">"
+ "<tr><th><h4><b r>"
+ "Quantity"
+ "</h4></th<th><h4>"
+ "Item"
+ "</h4></th><th><h4>"
+ "Unit Price"
+ "</h4></th></th><h4>"
+ "Total Price"
+ "</h4></th></tr>";
pageBottom = "</body></html>";
}
protected void processRequest( HttpServletRequ est request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
HttpSession session = request.getSess ion();
if (session.isNew( ) || session == null) {
sessionError( request, response);
}
String userID;
if (session.getAtt ribute("userID" ) != null) {
userID = (String)session .getAttribute(" userID");
} else {
sessionError( request, response);
userID = "";
}
Integer cartCount;
if (session.getAtt ribute("cartCou nt") != null)
{
cartCount = (Integer)sessio n.getAttribute( "cartCount" );
} else {
sessionError( request, response);
cartCount = Integer.valueOf (0);
}
if (session.getAtt ribute("pastOrd ers") != null)
{
pastOrders = (Hashtable)
session.getAttr ibute("pastOrde rs");
} else {
sessionError( request, response);
pastOrders = new Hashtable();
}
if (session.getAtt ribute("invTrac ker") != null)
{
invTracker = (InvTrackerHW3)
session.getAttr ibute("invTrack er");
}
String shiptoname;
String streetaddress;
String city;
String state;
String zip;
String shipservice;
String cctype;
String ccname;
String ccnum;
String ccexpmonth;
String ccexpyear;
// Shipping information
Hashtable shipHash;
if ((session.getAt tribute("shippi ng") != null))
{
shipHash = ((Hashtable)ses sion.getAttribu te("shipping")) ;
} else {
shipHash = new Hashtable();
}
String [] shipping = new String[5];
if (shipHash.get(u serID) != null) {
shipping = (String[])shipHash.get(u serID);
shiptoname = shipping[0];
streetaddress = shipping[1];
city = shipping[2];
state = shipping[3];
zip = shipping[4];
} else {
shiptoname = "";
streetaddress = "";
city = "";
state = "";
zip = "";
}
/*
if ((session.getAt tribute("shipto name") != null)) {
shiptoname = filter((String) session.getAttr ibute("shiptona me"))
*/
// Credit information
if ((session.getAt tribute("shipse rvice") != null)) {
shipservice = filter((String) session.getAttr ibute("shipserv ice"));
} else {
shipservice = "";
}
if ((session.getAt tribute("ccname ") != null)) {
ccname = filter((String) session.getAttr ibute("ccname") );
} else {
ccname = "";
}
if ((session.getAt tribute("cctype ") != null)) {
cctype = filter((String) session.getAttr ibute("cctype") );
} else {
cctype = "";
}
if ((session.getAt tribute("ccnum" ) != null)) {
ccnum = filter((String) session.getAttr ibute("ccnum")) ;
} else {
ccnum = "";
}
if ((session.getAt tribute("ccexpm onth") != null)) {
ccexpmonth = filter((String) session.getAttr ibute("ccexpmon th"));
} else {
ccexpmonth = "";
}
if ((session.getAt tribute("ccexpy ear") != null)) {
ccexpyear = filter((String) session.getAttr ibute("ccexpyea r"));
} else {
ccexpyear = "";
}
if (session.getAtt ribute("cart") != null && session.getAttr ibute("cartKeys ") != null)
cartData = new ShopCartDataHW3 ((Hashtable) session.getAttr ibute("cart"), (Hashtable)
session.getAttr ibute("cartKeys "));
else {
cartData = new ShopCartDataHW3 (new Hashtable(), new Hashtable());
}
String itemToAdd;
itemToAdd = (findItemAttrib ute(request, response));
if ((itemToAdd != null) && (cartData.getIt emID(itemToAdd) == null)) {
cartData.update ItemID(itemToAd d, 1);
}
if (itemToAdd != null) {
int defaultValue = (cartData.getQt y(itemToAdd).in tValue());
int x = getIntParameter (request, itemToAdd, defaultValue);
if (x < 0) {
// do nothing
} else {
cartData.update ItemID(itemToAd d, x);
}
}
Hashtable cart = new Hashtable(cartD ata.getCart());
Hashtable cartKeys = new Hashtable (cartData.getCa rtKeys());
session.setAttr ibute("cart", cart);
session.setAttr ibute("cartKeys ", cartKeys);
Integer numberOfKeys = new Integer (cartKeys.size( ));
session.setAttr ibute("cartCoun t", numberOfKeys);
runningTotal = 0;
Enumeration keyValues = cartKeys.elemen ts();
while(keyValues .hasMoreElement s()) {
String key = (String) keyValues.nextE lement();
if (key != null) {
setCartPage(key , cartData);
setConfirmItemL ist(key, cartData);
}
}
if (numberOfKeys.i ntValue() == 0) {
setCartPage(nul l, cartData);
}
String shippingAndCred it = loadShippingAnd Credit(shiptona me, streetaddress, city, state, zip, shipservice, cctype, ccname, ccnum, ccexpmonth, ccexpyear);
if (numberOfKeys.i ntValue() == 0) {
session.setAttr ibute("confirm" , "");
} else {
setConfirm(sess ion, cartKeys, numberOfKeys);
}
showPage(reques t, response, userID, cartKeys, numberOfKeys, shippingAndCred it);
}
private void showPage(HttpSe rvletRequest request,
HttpServletResp onse response, String userId, Hashtable cartKeys, Integer numberOfKeys, String shippingAndCred it)
throws ServletExceptio n, IOException {
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
out.println(pag eTop01 + pageTop02 + userID + pageTop03 + numberOfKeys + pageTop04);
out.println(shi ppingAndCredit) ;
out.println(pag eTable01Top);
Enumeration keyValues = cartKeys.elemen ts();
while(keyValues .hasMoreElement s()) {
String key = (String)keyValu es.nextElement( );
if (key != null) {
out.println(pag eItemList.get(k ey));
}
}
if (numberOfKeys.i ntValue() == 0) {
out.println(pag eItemEmpty);
}
out.println(pag eTable01Bottom + pageBottom);
out.close();
}
private String findItemAttribu te(HttpServletR equest request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
Enumeration paramNames = request.getPara meterNames();
while(paramName s.hasMoreElemen ts()) {
String paramName = (String) paramNames.next Element();
CatalogHW3 item = new CatalogHW3();
if (item.getItem(p aramName) != null) {
return paramName;
}
}
return null;
}
private void setCartPage(Str ing key, ShopCartDataHW3 cartData) {
String pageItemFormat0 0 = "<form action=\"ShopCa rtServletHW3\" method=\"post\" ><tr bgcolor=\"white \"><td align=\"center\ ">"
+ "<input type=\text\" name=\"";
String pageItemFormat0 1 = "\" value=\"";
String pageItemFormat0 2 = "\" size=\"3\" align=\"right\" >"
+ "<input type=\"submit\" name=\"Update\" value=\"Update\ " />"
+ "<br>";
String pageItemFormat0 3 = "</td><td><img src=\"";
String pageItemFormat0 4 = "\" align=\"middle\ " width=\"48\" height=\"48\"> ";
String pageItemFormat0 5 = "</td><td align=\"right\" >";
String pageItemFormat0 6 = "</td><td align=\"right\" >";
String pageItemFormat0 7 = "</td></tr></form>";
DecimalFormat f = new DecimalFormat() ;
if (key != null) {
int qtyOnHand = invTracker.getQ tyOnHand(key);
int qtyAvailable = qtyOnHand - cartData.getQty (key).intValue( );
if (qtyAvailable < 0) {
cartData.update ItemID(key, invTracker.getQ tyOnHand(key));
qtyAvailable = 0;
}
double total = ((cartData.getQ ty(key).intValu e() * cartData.getCos t(key)));
pageItemList.pu t(key, pageItemFormat0 0
+ cartData.getIte mID(key)
+ pageItemFormat0 1
+ cartData.getQty (key)
+ pageItemFormat0 2
+ qtyAvaliable + " More Avaliable "
+ pageItemFormat0 3
+ cartData.getIma gePath(key)
+ pageItemFormat0 4
+ cartData.getDes cription(key)
+ pageItemFormat0 5
+ "$" + f.format(cartDa ta.getCost(key) )
+ pageItemFormat0 6
+ "$" + f.format(total)
+ pageItemFormat0 7);
runningTotal = total + runningTotal;
} else {
pageItemEmpty = "<tr bgcolor=\"white \"><td colspan=\"4\" align=\"center\ ">"
+ "Your Shopping Cart is empty ... Please buy something."
+ "</td></tr>";
runningTotal = 0;
}
pageTable01Bott om = "<tr><td colspan=\"4\" align=\"Right\" ><h4> Total Order: $ "
+ f.format(runnin gTotal)
+ "</h4></td></tr></table>";
}
}
private void setConfirmItemL ist(String key, ShopCartDataHW3 cartData) {
confirmTableTop = "<center><h 3>"
+ "Order Details"
+ "<table border=\"1\" cellpadding=\"1 0\" align=\"center\ " valign=\"middle \">"
+ "<tr><th><h4><b r>"
+ "Quantity"
+ "</h4></th<th><h4>"
+ "Item"
+ "</h4></th><th><h4>"
+ "Unit Price"
+ "</h4></th></th><h4>"
+ "Total Price"
+ "</h4></th></tr>";
String confirmItemForm at00 = "<tr bgcolor=\"white \"><td align=\"center\ ">";
String confirmItemForm at01 = "<td align=\"right\" >";
String confirmItemForm at02 = "</td><td>";
String confirmItemForm at03 = "<img src =\"";
String confirmItemForm at04 = "\" align=\"middle\ " width=\"48\" height=\"48\"> ";
String confirmItemForm at05 = "</td><td align=\"right\" >";
String confirmItemForm at06 = "</td><td align=\right\"> ";
String confirmItemForm at07 = "</td></tr>";
DecimalFormat f = new DecimalFormat() ;
if (key != null) {
double total = ((cartData.getQ ty(key).intValu e() * cartData.getCos t(key)));
confirmItemList .put(key,
confirmItemForm at01
+ cartData.getQty (key)
+ confirmItemForm at02
+ confirmItemForm at03
+ cartData.getIma gePath(key)
+ confirmItemForm at04
+ cartData.getDes cription(key)
+ confirmItemForm at05
+ "$" + f.format(cartDa ta.getCost(key) )
+ confirmItemForm at06
+ "$" + f.format(total)
+ confirmItemForm at07);
}
confirmTable01B ottom = "<tr><td colspan=\"4\" align=\"Right\" ><h4>TOTAL ORDER: $ "
+ f.format(runnin gTotal)
+ "</h4></td></tr></table>";
}
private void setConfirm(Http Session session,
Hashtable cartKeys, Integer numberOfKeys)
throws ServletExceptio n, IOException {
StringBuffer confirm = new StringBuffer(co nfirmTableTop);
Enumeration keyValues = cartKeys.elemen ts();
while(keyValues .hasMoreElement s()) {
String key = (String)keyValu es.nextElement( );
if (key != null) {
confirm.append( (String)
confirmItemList .get(key));
}
}
if (key != null) {
confirm.append( (String)
confirmItemList .get(key));
}
}
confirm.append( confirmTable01B ottom);
session.setAttr ibute("confirm" , confirm.toStrin g());
}
private String loadShippingAnd Credit(String shiptonmae, String streetaddress, String city, String state, String zip, String shipservice, String cctype, String ccname, String ccnum, String ccexpmonth, String ccexyear) {
String credit01;
String credit02;
String credit03;
String ship01;
String ship02;
String ship03;
String ship04;
String ship05;
String ship06;
credit01 = "<form action=\"PurchC onfServletHW3\" method=\"post\" >"
+ "<table border=\"1\" cellpadding=\"1 0\" bgcolor=\"navy\ " align\"center\" >";
ship01 = "<center><h 3>"
+ "Please provide your billing and shipping information: "
+ "<input type=\"submit\" name=\"Submit Order\" value=\"Submit Order\" />"
+ "</h3></hr>";
String
bill01 = "<tr><td bgcolor=\"white \">"
+ "Card Type:"
+ "<br>"
+ "<select name=\"cctype\" >"
+ "<option value=\"Visa\" selected=\"sele cted\"> Visa</option>"
+ "<option value=\"MasterC ard\" selected=\"sele cted\"> MasterCard</option>"
+ "<option value=\"America n Express\" selected=\"sele cted\">American Express</option>"
+ "</select><br>"
+ "Card Number:"
+ "<br>"
+ "<input type=\"text\" name=\"ccnum\" value=\"";
credit02 = "\"><br>"
+ "Cardholder Name:"
+ "<br>"
+ "<input type=\"text\" name=\"ccname\" value=\"";
credit03 = "\"><br>"
+ "Expiration Date:"
+ "<br>"
+ "<select name=\"ccexpmon th\">"
+ "<option value=\"Jan\">J an</option>"
+ "<option value=\"Feb\">F eb</option>"
+ "<option value=\"Mar\">M ar</option>"
+ "<option value=\"Apr\">A pr</option>"
+ "<option value=\"May\">M ay</option>"
+ "<option value=\"Jun\">J un</option>"
+ "<option value=\"Jul\">J ul</option>"
+ "<option value=\"Aug\">A ug</option>"
+ "<option value=\"Sep\">S ep</option>"
+ "<option value=\"Oct\">O ct</option>"
+ "<option value=\"Nov\">N ov</option>"
+ "<option value=\"Dec\">D ec</option>"
+ "</select>"
+ "</td>";
String
ship00 = "<td bgcolor=\"white \">"
+ "Ship To Name:"
+ "<br>"
+ "<input type=\"text\" name=\"shiptona me\" size=\"37\" value=\"";
ship02 = "\"<br>"
+ "Street Address:"
+ "<br>"
+ + "<input type=\"text\" name=\"streetad dress\" size=\"37\" value=\"";
ship03 = "\"<br>"
+ "City State Zip:"
+ "<br>"
+ "<input type=\"text\" name=\"city\" size=\"20\" value=\"";
ship04 = "\">"
+ "<input type=\"text\" name=\"state\" size=\"2\" value=\"";
ship05 = "\">"
+ "<input type=\"text\" name=\"zip\" size=\"5\" value=\"";
ship06 = "\"</td>";
String
ship00a = "<td bgcolor=\"white \">"
+ "<input type=\"radio\" checked=\"check ed\" name=\"shipserv ice\" value=\"UPS Ground\">UPS Ground"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipserv ice\" value=\"UPS 2nd Day Air\">UPS 2nd Day Air"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipserv ice\" value=\"FedEx Priority\">FedE x Priority"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipserv ice\" value=\"FedEx Ultra\">FedEx Ultra"
+ "</td>";
String
ship00c = "</tr>"
+ "</table></form>";
return credit01
+ ship01
+ bill01
+ ccnum
+ credit02
+ ccname
+ credit03
+ ship00
+ shiptoname
+ ship02
+ ship03
+ streetaddress
+ city
+ ship04
+ state
+ ship05
+ zip
+ ship06
+ ship00a
+ ship00c;
}
private void sessionError(Ht tpServletReques t request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
String sessionErrorFor m;
sessionErrorFor m = "<form action=\"RegLog inServletHW3\" method=\"post\" ><tr bgcolor=\"white \"> <td align=\"center\ ">"
+ "<h3 align=\"center\ ">Your request has not been processed - some isseues were found. <br> Please return to the Login page. </h3>"
+ "<input type=\"submit\" name=\"Go to Login\" value=\"Go to Login\" /></form>";
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
out.println(pag eTop01 + sessionErrorFor m);
out.close();
}
private String filter(String input) {
StringBuffer filter = new StringBuffer(in put.length());
char c;
for(int i=0; i<input.length( ); i++) {
c = input.charAt(i) ;
if (c == '<') {
filtered.append ("<");
} else if ( c == '>') {
filtered.append (">");
} else if ( c == '"') {
filtered.append (""");
} else if (c == '&') {
filtered.append ("&");
} else {
filtered.append (c);
}
}
return(filtered .toString());
}
private int getIntParameter (HttpSevletRequ est request,
String paramName,
int defaultValue) {
String paramString = request.getPara meter(paramName );
int paramValue;
try {
paraValue = Integer.parseIn t(paramString);
} catch (NumberFormatEx ception nfe) { // null or bad format
paramValue = defaultValue;
}
return(paramVal ue);
}
//<editor-fold defaultstate="c ollapsed" desc="HttpServl et methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code>method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServl etRequest request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
processRequest( request, response);
}
/** Handles the HTTP <code>POST</code>method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServ letRequest request,
HttpServletResp onse response)
throws ServletExceptio n, IOException {
processRequest( request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo( ) {
return "Short description";
}
// </editor-fold>
}
Comment