<%@ page import="com.apz.pirisale.*" %> <% String mAction = request.getParameter("action"); Object objCustomerBasket = session.getAttribute("basket"); boolean mActive = (session.getAttribute("active") != null); if(!mActive) { // redirect to need login page } if(objCustomerBasket == null) { response.sendRedirect("error.jsp?errorText=Basket not initialised"); return; } if(mAction == null) { response.sendRedirect("error.jsp?errorText=Missing parameter"); return; } Basket customerBasket = (Basket)objCustomerBasket; if("addItem".equals(mAction)) { String szItemID = request.getParameter("itemID"); String szQuantity = request.getParameter("buyQuantity"); if((szItemID == null) || (szQuantity == null)) { response.sendRedirect("error.jsp?errorText=Missing parameter"); return; } try { long itemID = Long.parseLong(szItemID); int quantity = Integer.parseInt(szQuantity); try { customerBasket.addItem(itemID, quantity); } catch(Exception e) { response.sendRedirect("error.jsp?errorText=" + e.toString()); return; } } catch(NumberFormatException e) { response.sendRedirect("error.jsp?errorText=Parameter is not numeric"); return; } } if("removeItem".equals(mAction)) { String szItemIndex = request.getParameter("itemIndex"); if (szItemIndex == null) { response.sendRedirect("error.jsp?errorText=Missing parameter"); return; } try { int itemIndex = Integer.parseInt(szItemIndex); try { customerBasket.removeItem(itemIndex); } catch(Exception e) { response.sendRedirect("error.jsp?errorText=" + e.toString()); return; } } catch(NumberFormatException e) { response.sendRedirect("error.jsp?errorText=Parameter is not numeric"); return; } } response.sendRedirect("basket.jsp"); %>