请教!struts的购物车为什么不能添加商品??
这是shoppingCart的bean
public class ShoppingCart {
private double totalPrice;
private Map<Integer,Line> lines=new HashMap<Integer,Line>();
public void addItem(Line line){
Integer bookId=line.getBook().getId();
if(lines.containsKey(bookId)){
Line oldLine=lines.get(bookId);
int oldQuantity=oldLine.getQuantity();
oldQuantity=+line.getQuantity();
oldLine.setQuantity(oldQuantity);
oldLine.setCost(oldLine.getLineCost());
lines.put(bookId, oldLine);
}else{
line.setCost(line.getLineCost());
lines.put(bookId, line);
}
}
}
jsp里面
<jsp:useBean id="cart" class="org.ysll.model.biz.entity.ShoppingCart" scope="session"></jsp:useBean>
<%
List<Line> lines=new ArrayList<Line>();
Map<Integer,Line>bookMap=cart.getLines();
Set<Integer>key=bookMap.keySet();
Iterator it=key.iterator();
while(it.hasNext()){
Integer i=(Integer)it.next();
Line line=(Line)bookMap.get(i);
lines.add(line);
out.println(line.getBook().getName());
}
%>
<TABLE cellSpacing=0 cellPadding=3 border=0>
<TBODY>
<!-- Header Row -->
<TR bgColor=#cccccc>
<TD noWrap align=middle><FONT size=2><B>书号</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>书名</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>个数</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>价格</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>购买总价格</B></FONT></TD>
</TR>
<%for (int i = 0; i < lines.size(); i++) {
Line l = lines.get(i);
%>
<TR bgColor=#ffffff>
<TD ><FONT size=2><B><%=l.getBook().getId()%><BR>
</B></FONT></TD>
<!-- name and description for item -->
<TD ><FONT size=2><B><%=l.getBook().getName()%></B></FONT></TD>
<!-- Qty input box -->
<TD ><FONT size=2><B><%=l.getQuantity()%></B></FONT></TD>
<!-- Unit price for item -->
<TD ><FONT size=2><B><%=l.getBook().getPrice()%><BR>
</B></FONT></TD>
<!-- Extended price for item -->
<TD>
<TABLE cellSpacing=2 cellPadding=3 border=0>
<TBODY>
<TR>
<TD align=right bgColor=#ffcc00><FONT size=2><B><%=l.getCost()%><BR>
</B></FONT></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<%}
%>
请问为什么不能加进去呢??急死我了..
public class ShoppingCart {
private double totalPrice;
private Map<Integer,Line> lines=new HashMap<Integer,Line>();
public void addItem(Line line){
Integer bookId=line.getBook().getId();
if(lines.containsKey(bookId)){
Line oldLine=lines.get(bookId);
int oldQuantity=oldLine.getQuantity();
oldQuantity=+line.getQuantity();
oldLine.setQuantity(oldQuantity);
oldLine.setCost(oldLine.getLineCost());
lines.put(bookId, oldLine);
}else{
line.setCost(line.getLineCost());
lines.put(bookId, line);
}
}
}
jsp里面
<jsp:useBean id="cart" class="org.ysll.model.biz.entity.ShoppingCart" scope="session"></jsp:useBean>
<%
List<Line> lines=new ArrayList<Line>();
Map<Integer,Line>bookMap=cart.getLines();
Set<Integer>key=bookMap.keySet();
Iterator it=key.iterator();
while(it.hasNext()){
Integer i=(Integer)it.next();
Line line=(Line)bookMap.get(i);
lines.add(line);
out.println(line.getBook().getName());
}
%>
<TABLE cellSpacing=0 cellPadding=3 border=0>
<TBODY>
<!-- Header Row -->
<TR bgColor=#cccccc>
<TD noWrap align=middle><FONT size=2><B>书号</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>书名</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>个数</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>价格</B></FONT></TD>
<TD noWrap align=middle><FONT size=2><B>购买总价格</B></FONT></TD>
</TR>
<%for (int i = 0; i < lines.size(); i++) {
Line l = lines.get(i);
%>
<TR bgColor=#ffffff>
<TD ><FONT size=2><B><%=l.getBook().getId()%><BR>
</B></FONT></TD>
<!-- name and description for item -->
<TD ><FONT size=2><B><%=l.getBook().getName()%></B></FONT></TD>
<!-- Qty input box -->
<TD ><FONT size=2><B><%=l.getQuantity()%></B></FONT></TD>
<!-- Unit price for item -->
<TD ><FONT size=2><B><%=l.getBook().getPrice()%><BR>
</B></FONT></TD>
<!-- Extended price for item -->
<TD>
<TABLE cellSpacing=2 cellPadding=3 border=0>
<TBODY>
<TR>
<TD align=right bgColor=#ffcc00><FONT size=2><B><%=l.getCost()%><BR>
</B></FONT></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<%}
%>
请问为什么不能加进去呢??急死我了..
...全文
相关推荐
jsp+struts2购物车
【业务逻辑】:购物车的核心业务逻辑包括:1. 添加商品:用户选择商品后,将商品信息发送给服务器,Struts2 Action接收到请求后,将商品添加到购物车。2.
struts2购物车
### Struts2购物车系统分析#### 一、系统概述在本案例中,我们探讨一个基于Struts2框架的购物车系统实现。
添加了struts和Hibernate的简单购物车代码
**Action处理**:当用户点击“添加到购物车”按钮时,会触发一个Struts Action,这个Action会调用服务层方法来处理商品的添加操作,并更新购物车状态。4.
Struts购物车
在购物车场景中,我们可能有展示商品列表的页面、添加商品到购物车的页面、查看购物车内容的页面以及结账页面等。
购物车 java struts
**编写Struts Action**:创建一个`CartAction`类,实现添加商品到购物车、显示购物车内容、清空购物车等功能。4.


