Shopping Cart Apps in JSP

ShoppingCart.jsp Shopping cart java.util.Enumeration parms; java.util.Enumeration values; parms = request.getParameterNames(); values = request.getParameterNames(); while(parms.hasMoreElements()) { String name = (String) parms.nextElement(); String value = (String) values.nextElement(); session.setAttribute(name, value); }

Add to shopping cart

name="scissors"> Scissors
name="book"> Book
name="pen"> Pen
name="bottle"> Bottle
name="glass"> Glass


cart.jsp Shopping cart

The shopping cart

"); } ]]> remove.jsp Shopping cart java.util.Enumeration parms; parms = request.getParameterNames(); while(parms.hasMoreElements()) { String name = (String) parms.nextElement(); session.removeAttribute(name); }

Remove items from cart

<% if (session.getAttribute("scissors") != null) { %> <% } %> <% if (session.getAttribute("book") != null) { %> <% } %> <% if (session.getAttribute("pen") != null) { %> <% } %> <% if (session.getAttribute("bottle") != null) { %> <% } %> <% if (session.getAttribute("glass") != null) { %> <% } %>
Scissors
Book
Pen
Bottle
Glass


Comments

Popular Posts