I am a beginner to
Java. I am doing an assignment of a Shopping cart application. Below is the action class I have created. I want a number to display in the
JSP page each time the size of the array increases. How do I call the arraylist from the
servlet in the JSP page? Any help would be greatly appreciated. Thank You.
public class ItemAddToCartAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
try {
Hashtable item = new Hashtable();
item.put("brand", request.getParameter("brand"));
item.put("color", request.getParameter("color"));
item.put("size", request.getParameter("size"));
item.put("price", request.getParameter("price"));
item.put("shipping", request.getParameter("shipping"));
if (session.getAttribute("cart") == null) {
ArrayList cart = new ArrayList();
cart.add(item);
session.setAttribute("cart", cart);
}
else {
ArrayList cartFromSession = (ArrayList)
session.getAttribute("cart");
cartFromSession.add(item);
session.setAttribute("cart",cartFromSession);
}
} catch (Exception e) {
System.out.println("Exception occured");
return mapping.findForward("Failure");
}
return mapping.findForward("SUCCESS");
}
}