想请问下关于购物车如何实现

能说具体点吗?如何保存用户买的商品,谢谢!

通过session保存的。

petstore中就有一个shoppingcart,使用了EJB中的statefull session bean.

每个用户点按商品时,将该商品保存到该用户的session中,用户离开结账时,再从seesion中获取该用户购买商品的清单。

I think all serious website will persist shoppingcart info into database, petstore store uncheck item inside httpSession, that's not safe, plus it make clustering bit difficult to be realized.
People do usually use httpSession id ( thru coookie or URL rewrite) to identify unauthenticated client, after you login, they will switch to your user id.

Cheers
-Wanchun

这样的话,只能记录一个session,会被覆盖的啊

To Gentoo,
Sorry, I did not understand your question.

我意思是,比如你买了商品a那么会把a加入session,假如你又买了商品B
那么会把B加入SESSION,这么不是b覆盖了a?
session.setAttribute("shop","a");
session.setAttribute("shop","b");

可以用一个Vector,
Vector放入session中,
Vector shopVec=new Vector();
shopVec.addElement(a);
shopVec.addElement(b);
应该可以的;