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

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

banq
2002-12-07 12:31
通过session保存的。

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

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

Jevang
2002-12-07 13:10
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

gentoo
2002-12-07 15:34
这样的话,只能记录一个session,会被覆盖的啊

Jevang
2002-12-08 02:28
To Gentoo,

Sorry, I did not understand your question.

gentoo
2002-12-09 09:25
我意思是,比如你买了商品a那么会把a加入session,假如你又买了商品B

那么会把B加入SESSION,这么不是b覆盖了a?

session.setAttribute("shop","a");

session.setAttribute("shop","b");

nmg
2002-12-09 10:01
可以用一个Vector,

Vector放入session中,

Vector shopVec=new Vector();

shopVec.addElement(a);

shopVec.addElement(b);

应该可以的;

猜你喜欢