ArrayList theCart = new ArrayList();
if (session.getAttribute("cart") != null){
theCart = (ArrayList)session.getAttribute("cart");
}
beans.ProductFormBean theBean = (ProductFormBean)form;
managers.ProductManager manager = new managers.ProductManager();
if (theBean.getProductId() == 0) {
request.setAttribute("message", "Product Id is required");
nextPage = mapping.findForward("failure");
}
else if (theBean.getQuantity() == 0) {
request.setAttribute("message", "Quantity is required");
nextPage = mapping.findForward("failure");
}
else{
try{
theBean = manager.find(theBean);
if (theBean == null){
nextPage = mapping.findForward("failure");
request.setAttribute("message", "Error locating product");
}
else{
request.setAttribute("message", "Product Added to Cart");
theCart.add(theBean);
theCart.add(theBean);
//request.setAttribute("cart", theCart);
session.setAttribute("cart",theCart);
nextPage = mapping.findForward("success");
}
}
catch (Exception e){
request.setAttribute("message", e+" "+"exception error");
nextPage = mapping.findForward("failure");
}
// request.setAttribute("cart", theBean);
}
return nextPage;