Java Reference
In-Depth Information
String choice = request.getParameter("Option");
/*
Above parameter determines whether user wishes
to select another product, add the current order
to the cart, remove an existing order from
the cart or proceed to the checkout.
User is redirected to the appropriate page
(after any required updating of the shopping
cart session variable has been carried out).
*/
if (choice.equals("Next"))
response.sendRedirect("ShoppingCart.html");
if (choice.equals("Checkout"))
response.sendRedirect("Checkout");
if (choice.equals("Add"))
{
doAdd(cart,request);
response.sendRedirect("ShoppingCart.html");
}
if (choice.equals("Remove"))
//Not really possible for it to be
//anything else, but play safe!
{
doRemove(cart);
response.sendRedirect("ShoppingCart.html");
}
}
private void doAdd(HttpSession cart,
HttpServletRequest request)
{
String currentProduct =
(String)cart.getAttribute("currentProd");
String qty = request.getParameter("Qty");
//Value of weight entered by user retrieved here.
if (qty!=null)
//Check that user actually entered a value!
{
if (currentProduct.equals("Apples"))
cart.setAttribute("Apples",qty);
else
cart.setAttribute("Pears",qty);
}
}
Search WWH ::




Custom Search