I made sure I closed all the bracket, why do i still get the error.
on line 360, 424, 425 and 607
Please help
/*
* ShopCartServletHW3.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.http.*;
/**
*
* @author Administrator
* @version
*/
public class ShopCartServletHW3 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 pageTable01Bottom;
private String pageBottom;
private String pageItemEmpty;
private String confirmTable01Bottom;
private String confirmTableTop;
private String confirmItemEmpty;
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 ServletException {
PageTop01 = "<html>"
+ "<head>"
+ "<title>Blue 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=\"RegLoginServletHW3\"> [Log Out]</a>"
+ " "
+ "<a href=\"CatServletHW3\">[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><h3>"
+ "Please review sections:"
+ "</h3><table border=\"1\" cellpadding=\"10\" align=\"center\" valign=\"middle\" bgcolor=\"navy\">"
+ "<tr><th><h4><br>"
+ "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(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
if (session.isNew() || session == null) {
sessionError( request, response);
}
String userID;
if (session.getAttribute("userID") != null) {
userID = (String)session.getAttribute("userID");
} else {
sessionError( request, response);
userID = "";
}
Integer cartCount;
if (session.getAttribute("cartCount") != null)
{
cartCount = (Integer)session.getAttribute("cartCount");
} else {
sessionError( request, response);
cartCount = Integer.valueOf(0);
}
if (session.getAttribute("pastOrders") != null)
{
pastOrders = (Hashtable)
session.getAttribute("pastOrders");
} else {
sessionError( request, response);
pastOrders = new Hashtable();
}
if (session.getAttribute("invTracker") != null)
{
invTracker = (InvTrackerHW3)
session.getAttribute("invTracker");
}
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.getAttribute("shipping") != null))
{
shipHash = ((Hashtable)session.getAttribute("shipping"));
} else {
shipHash = new Hashtable();
}
String [] shipping = new String[5];
if (shipHash.get(userID) != null) {
shipping = (String[])shipHash.get(userID);
shiptoname = shipping[0];
streetaddress = shipping[1];
city = shipping[2];
state = shipping[3];
zip = shipping[4];
} else {
shiptoname = "";
streetaddress = "";
city = "";
state = "";
zip = "";
}
/*
if ((session.getAttribute("shiptoname") != null)) {
shiptoname = filter((String) session.getAttribute("shiptoname"))
*/
// Credit information
if ((session.getAttribute("shipservice") != null)) {
shipservice = filter((String) session.getAttribute("shipservice"));
} else {
shipservice = "";
}
if ((session.getAttribute("ccname") != null)) {
ccname = filter((String) session.getAttribute("ccname"));
} else {
ccname = "";
}
if ((session.getAttribute("cctype") != null)) {
cctype = filter((String) session.getAttribute("cctype"));
} else {
cctype = "";
}
if ((session.getAttribute("ccnum") != null)) {
ccnum = filter((String)session.getAttribute("ccnum"));
} else {
ccnum = "";
}
if ((session.getAttribute("ccexpmonth") != null)) {
ccexpmonth = filter((String) session.getAttribute("ccexpmonth"));
} else {
ccexpmonth = "";
}
if ((session.getAttribute("ccexpyear") != null)) {
ccexpyear = filter((String) session.getAttribute("ccexpyear"));
} else {
ccexpyear = "";
}
if (session.getAttribute("cart") != null && session.getAttribute("cartKeys") != null)
cartData = new ShopCartDataHW3((Hashtable) session.getAttribute("cart"), (Hashtable)
session.getAttribute("cartKeys"));
else {
cartData = new ShopCartDataHW3(new Hashtable(), new Hashtable());
}
String itemToAdd;
itemToAdd = (findItemAttribute(request, response));
if ((itemToAdd != null) && (cartData.getItemID(itemToAdd) == null)) {
cartData.updateItemID(itemToAdd, 1);
}
if (itemToAdd != null) {
int defaultValue = (cartData.getQty(itemToAdd).intValue());
int x = getIntParameter(request, itemToAdd, defaultValue);
if (x < 0) {
// do nothing
} else {
cartData.updateItemID(itemToAdd, x);
}
}
Hashtable cart = new Hashtable(cartData.getCart());
Hashtable cartKeys = new Hashtable (cartData.getCartKeys());
session.setAttribute("cart", cart);
session.setAttribute("cartKeys", cartKeys);
Integer numberOfKeys = new Integer (cartKeys.size());
session.setAttribute("cartCount", numberOfKeys);
runningTotal = 0;
Enumeration keyValues = cartKeys.elements();
while(keyValues.hasMoreElements()) {
String key = (String) keyValues.nextElement();
if (key != null) {
setCartPage(key, cartData);
setConfirmItemList(key, cartData);
}
}
if (numberOfKeys.intValue() == 0) {
setCartPage(null, cartData);
}
String shippingAndCredit = loadShippingAndCredit(shiptoname, streetaddress, city, state, zip, shipservice, cctype, ccname, ccnum, ccexpmonth, ccexpyear);
if (numberOfKeys.intValue() == 0) {
session.setAttribute("confirm", "");
} else {
setConfirm(session, cartKeys, numberOfKeys);
}
showPage(request, response, userID, cartKeys, numberOfKeys, shippingAndCredit);
}
private void showPage(HttpServletRequest request,
HttpServletResponse response, String userId, Hashtable cartKeys, Integer numberOfKeys, String shippingAndCredit)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println(pageTop01 + pageTop02 + userID + pageTop03 + numberOfKeys + pageTop04);
out.println(shippingAndCredit);
out.println(pageTable01Top);
Enumeration keyValues = cartKeys.elements();
while(keyValues.hasMoreElements()) {
String key = (String)keyValues.nextElement();
if (key != null) {
out.println(pageItemList.get(key));
}
}
if (numberOfKeys.intValue() == 0) {
out.println(pageItemEmpty);
}
out.println(pageTable01Bottom + pageBottom);
out.close();
}
private String findItemAttribute(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
CatalogHW3 item = new CatalogHW3();
if (item.getItem(paramName) != null) {
return paramName;
}
}
return null;
}
private void setCartPage(String key, ShopCartDataHW3 cartData) {
String pageItemFormat00 = "<form action=\"ShopCartServletHW3\" method=\"post\"><tr bgcolor=\"white\"><td align=\"center\">"
+ "<input type=\text\" name=\"";
String pageItemFormat01 = "\" value=\"";
String pageItemFormat02 = "\" size=\"3\" align=\"right\">"
+ "<input type=\"submit\" name=\"Update\" value=\"Update\" />"
+ "<br>";
String pageItemFormat03 = "</td><td><img src=\"";
String pageItemFormat04 = "\" align=\"middle\" width=\"48\" height=\"48\"> ";
String pageItemFormat05 = "</td><td align=\"right\">";
String pageItemFormat06 = "</td><td align=\"right\">";
String pageItemFormat07 = "</td></tr></form>";
DecimalFormat f = new DecimalFormat();
if (key != null) {
int qtyOnHand = invTracker.getQtyOnHand(key);
int qtyAvailable = qtyOnHand - cartData.getQty(key).intValue();
if (qtyAvailable < 0) {
cartData.updateItemID(key, invTracker.getQtyOnHand(key));
qtyAvailable = 0;
}
double total = ((cartData.getQty(key).intValue() * cartData.getCost(key)));
pageItemList.put(key, pageItemFormat00
+ cartData.getItemID(key)
+ pageItemFormat01
+ cartData.getQty(key)
+ pageItemFormat02
+ qtyAvaliable + " More Avaliable "
+ pageItemFormat03
+ cartData.getImagePath(key)
+ pageItemFormat04
+ cartData.getDescription(key)
+ pageItemFormat05
+ "$" + f.format(cartData.getCost(key))
+ pageItemFormat06
+ "$" + f.format(total)
+ pageItemFormat07);
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;
}
pageTable01Bottom = "<tr><td colspan=\"4\" align=\"Right\"><h4> Total Order: $ "
+ f.format(runningTotal)
+ "</h4></td></tr></table>";
}
}
private void setConfirmItemList(String key, ShopCartDataHW3 cartData) {
confirmTableTop = "<center><h3>"
+ "Order Details"
+ "<table border=\"1\" cellpadding=\"10\" align=\"center\" valign=\"middle\">"
+ "<tr><th><h4><br>"
+ "Quantity"
+ "</h4></th<th><h4>"
+ "Item"
+ "</h4></th><th><h4>"
+ "Unit Price"
+ "</h4></th></th><h4>"
+ "Total Price"
+ "</h4></th></tr>";
String confirmItemFormat00 = "<tr bgcolor=\"white\"><td align=\"center\">";
String confirmItemFormat01 = "<td align=\"right\">";
String confirmItemFormat02 = "</td><td>";
String confirmItemFormat03 = "<img src =\"";
String confirmItemFormat04 = "\" align=\"middle\" width=\"48\" height=\"48\"> ";
String confirmItemFormat05 = "</td><td align=\"right\">";
String confirmItemFormat06 = "</td><td align=\right\">";
String confirmItemFormat07 = "</td></tr>";
DecimalFormat f = new DecimalFormat();
if (key != null) {
double total = ((cartData.getQty(key).intValue() * cartData.getCost(key)));
confirmItemList.put(key,
confirmItemFormat01
+ cartData.getQty(key)
+ confirmItemFormat02
+ confirmItemFormat03
+ cartData.getImagePath(key)
+ confirmItemFormat04
+ cartData.getDescription(key)
+ confirmItemFormat05
+ "$" + f.format(cartData.getCost(key))
+ confirmItemFormat06
+ "$" + f.format(total)
+ confirmItemFormat07);
}
confirmTable01Bottom = "<tr><td colspan=\"4\" align=\"Right\"><h4>TOTAL ORDER: $ "
+ f.format(runningTotal)
+ "</h4></td></tr></table>";
}
private void setConfirm(HttpSession session,
Hashtable cartKeys, Integer numberOfKeys)
throws ServletException, IOException {
StringBuffer confirm = new StringBuffer(confirmTableTop);
Enumeration keyValues = cartKeys.elements();
while(keyValues.hasMoreElements()) {
String key = (String)keyValues.nextElement();
if (key != null) {
confirm.append((String)
confirmItemList.get(key));
}
}
if (key != null) {
confirm.append((String)
confirmItemList.get(key));
}
}
confirm.append(confirmTable01Bottom);
session.setAttribute("confirm", confirm.toString());
}
private String loadShippingAndCredit(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=\"PurchConfServletHW3\" method=\"post\">"
+ "<table border=\"1\" cellpadding=\"10\" bgcolor=\"navy\" align\"center\">";
ship01 = "<center><h3>"
+ "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=\"selected\"> Visa</option>"
+ "<option value=\"MasterCard\" selected=\"selected\"> MasterCard</option>"
+ "<option value=\"American Express\" selected=\"selected\">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=\"ccexpmonth\">"
+ "<option value=\"Jan\">Jan</option>"
+ "<option value=\"Feb\">Feb</option>"
+ "<option value=\"Mar\">Mar</option>"
+ "<option value=\"Apr\">Apr</option>"
+ "<option value=\"May\">May</option>"
+ "<option value=\"Jun\">Jun</option>"
+ "<option value=\"Jul\">Jul</option>"
+ "<option value=\"Aug\">Aug</option>"
+ "<option value=\"Sep\">Sep</option>"
+ "<option value=\"Oct\">Oct</option>"
+ "<option value=\"Nov\">Nov</option>"
+ "<option value=\"Dec\">Dec</option>"
+ "</select>"
+ "</td>";
String
ship00 = "<td bgcolor=\"white\">"
+ "Ship To Name:"
+ "<br>"
+ "<input type=\"text\" name=\"shiptoname\" size=\"37\" value=\"";
ship02 = "\"<br>"
+ "Street Address:"
+ "<br>"
+ + "<input type=\"text\" name=\"streetaddress\" 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=\"checked\" name=\"shipservice\" value=\"UPS Ground\">UPS Ground"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipservice\" value=\"UPS 2nd Day Air\">UPS 2nd Day Air"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipservice\" value=\"FedEx Priority\">FedEx Priority"
+ "<br><br>"
+ "<input type=\"radio\" name=\"shipservice\" 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(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String sessionErrorForm;
sessionErrorForm = "<form action=\"RegLoginServletHW3\" 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.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println(pageTop01 + sessionErrorForm);
out.close();
}
private String filter(String input) {
StringBuffer filter = new StringBuffer(input.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(HttpSevletRequest request,
String paramName,
int defaultValue) {
String paramString = request.getParameter(paramName);
int paramValue;
try {
paraValue = Integer.parseInt(paramString);
} catch (NumberFormatException nfe) { // null or bad format
paramValue = defaultValue;
}
return(paramValue);
}
//<editor-fold defaultstate="collapsed" desc="HttpServlet 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(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Handles the HTTP <code>POST</code>method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}