怎么写购物车代码

1. Jsp写的购物车代码 这是其中的一段代码,要项目的话加445899710
【怎么写购物车代码】HttpSession session = request.getSession(false);
if(session==null){
dispatcher = request.getRequestDispatcher("show.jsp");
dispatcher.forward(request, response);
}
FoodBean foodBean = (FoodBean)session.getAttribute("FoodToAdd");
Map cart = (Map)session.getAttribute("cart");
if(cart==null){
cart = new HashMap();
session.setAttribute("cart", cart);
}
CartItemBean cartItem = (CartItemBean)cart.get(foodBean.getFoodID());
if(cartItem==null){
cart.put(foodBean.getFoodID(), new CartItemBean(foodBean,1));
}else{
cartItem.setNumber(cartItem.getNumber()+1);
}
2. 用JAVA+SERVLET+JAVABEAN写购物车代码 你用
写一个购物车的bean,里边有产品和数量
public class CarProduct {
private XXX XXX;
private int count;
public Book getXXX() {
return XXX;
}
public void setXXX(XXX XXX) {
this.XXX= XXX;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
用session存购物车里的东西,提交订单的时候,把购物车清空就行,
3. jsp购物车代码 //shopping.html shopping stor <body> ------------------------------------------------------------------//carts.jsp<%@page contentType="text/html;charset=ISO8859_1" %> <% cart.processRequest(); %>

    you have chosen these items: <% String []items=cart.getItems(); for(int i=0;i <%=items[i] %> <% } %>
<%@include file="shopping.htm" %>---------------------------------------------------------------------//DummyCart.java package test; import javax.servlet.http.*; import java.util.Vector; import java.util.Enumeration; public class DummyCart { Vector v = new Vector(); String submit=null; String item= null; private void addItem(String name) { v.addElement(name); } private void removeItem(String name) { v.removeElement(name); } public void setItem(String s) { item=s; } public void setSubmit(String s) { submit=s; } public String[] getItems() { String []s=new String[v.size()]; v.copyInto(s); return s; } public void processRequest() { if(submit==null) addItem(item); if(submit.equals("add")) addItem(item); else if (submit.equals("remove")) removeItem(item); reset(); } private void reset() { submit=null; item=null; } }---------------------------------------------------------------------- 上面是一个简单的例子,功能都能实现,对网页效果要求更漂亮些的可做一些修改 。
4. 急求java购物车代码 package bean;import java.util.ArrayList;import java.util.List;/** * * @author Administrator * 购物车类: * 为了方便将商品信息绑订到session上面而设计的一个 * 工具,提供了商品的添加,删除,列表,计价,清空,* 修改功能 。
*/public class Cart {//items属性:用来保存商品private List items = new ArrayList();/** * 将商品添加到购物车 */public boolean add(CartItem item){for(int i=0;i list(){return items;}/** * 商品总价 */public double cost(){double total = 0;for(int i=0;i