有关Httpsession绑定购物车的问题

FlyPig1983 2004-05-13 09:42:24
我在加入购物车的jsp页面中写了下面的代码(部分主要代码)
ShoppingControl control=new ShoppingControl();
String result;
session.setAttribute("shoeshop.cart",control.getShoppingCart());
result=control.addItem(control.getShoppingCart(),item);

其中ShoppingControl 是一个JavaBean 它其中包括有ShoppingCart这个远程接口
ShoppingCart我做成会话Bean。
我先初始化JavaBean 然后取出其中ShoppingCart,
然后将它与session绑定 在对其进行操作 但我发现在两台机器同时访问的时候 Session好像没有发挥它的作用,一个人购物条目 在另外一个人上面也出现了 不知道是不是绑定没有对

还有一个 在JSP页面中怎样弹出一个消息框
请各位多多指教!!
...全文
87 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
FlyPig1983 2004-05-14
  • 打赏
  • 举报
回复
谢谢两位
我的思想是每当一个人购物时就将一个远程接口(会话Bean ShoppingCart)给一个用户绑定,就是说当一个用户绑定了一个ShoppingCart后,ShoppingCart里面的属性(Items)是不是也自动被初始化为空的
CartItem 代码如下:
public class CartItem implements Serializable{

private String itemId;
private String shoename;
private Integer size;
private String material;
private String color;
private BigDecimal price;
private BigDecimal discount;
private BigDecimal disPrice;
private int quantity;
private BigDecimal total;
public BigDecimal getTotal(){return total;}
private void calculateTotal(){

total=this.disPrice.multiply(new BigDecimal(quantity));

}
public int getQuantity(){return quantity;}
public void setQuantity(int quantity){
this.quantity=quantity;
calculateTotal();
}

/**
* Gets the itemId
* @return Returns a String
*/
public String getItemId() {
return itemId;
}
/**
* Sets the itemId
* @param itemId The itemId to set
*/
public void setItemId(String itemId) {
this.itemId = itemId;
}
/**
* Gets the shoename
* @return Returns a String
*/
public String getShoename() {
return shoename;
}
/**
* Sets the shoename
* @param shoename The shoename to set
*/
public void setShoename(String shoename) {
this.shoename = shoename;
}
/**
* Gets the size
* @return Returns a Integer
*/
public Integer getSize() {
return size;
}
/**
* Sets the size
* @param size The size to set
*/
public void setSize(Integer size) {
this.size = size;
}
/**
* Gets the material
* @return Returns a String
*/
public String getMaterial() {
return material;
}
/**
* Sets the material
* @param material The material to set
*/
public void setMaterial(String material) {
this.material = material;
}
/**
* Gets the color
* @return Returns a String
*/
public String getColor() {
return color;
}
/**
* Sets the color
* @param color The color to set
*/
public void setColor(String color) {
this.color = color;
}
/**
* Gets the price
* @return Returns a BigDecimal
*/
public BigDecimal getPrice() {
return price;
}
/**
* Sets the price
* @param price The price to set
*/
public void setPrice(BigDecimal price) {
this.price = price;
}
/**
* Gets the discount
* @return Returns a BigDecimal
*/
public BigDecimal getDiscount() {
return discount;
}
/**
* Sets the discount
* @param discount The discount to set
*/
public void setDiscount(BigDecimal discount) {
this.discount = discount;
}
/**
* Gets the disPrice
* @return Returns a BigDecimal
*/
public BigDecimal getDisPrice() {
return disPrice;
}
/**
* Sets the disPrice
* @param disPrice The disPrice to set
*/
public void setDisPrice() {
BigDecimal a = this.price.multiply(this.discount);
this.disPrice=new BigDecimal(a.intValue()/10);
}
/**
* Sets the total
* @param total The total to set
*/
public void setTotal() {
calculateTotal();
}
}


Apollo47 2004-05-14
  • 打赏
  • 举报
回复
不知道你的CartItem是什么东东,很有可能是你把不同客户的商品都放在同一个容器里了(Vector)。
addItem方法也好像有问题。

FlyPig1983 2004-05-14
  • 打赏
  • 举报
回复
ShoppingControl这个类里面的addItem()只是调用ShoppingCart会话Bean里面的方法addItem(),
。我在ShoppingCart里面设置了一个属性Items(Vector)。

public class ShoppingCartBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;
private Vector items;
private Map itemMap=new HashMap();

public String addItem(CartItem item)
{
try{
CartItem cartItem=(CartItem)itemMap.get(item.getItemId());

if(cartItem==null)
{
cartItem=new CartItem();
cartItem=item;
itemMap.put(item.getItemId(),cartItem);
items=new Vector(itemMap.values());
return new String("成功加入购物车 ");
}
else
{
return new String("该商品已经加入购物车!!!");
}

}

这个就是购物车的主要代码 Item 类型 就是跟商品差不多拉 请多多指教
FlyPig1983 2004-05-14
  • 打赏
  • 举报
回复
时间紧迫 自己顶!!!
Sheepy 2004-05-13
  • 打赏
  • 举报
回复
需要知道ShoppingControl这个类是如何实现的。

弹出消息框请用javascript。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧