我要实现的功能就是和淘宝购物车的功能一样。当我查看购物车,假如里面有两件商品,当我去结算时,怎样在servlet中得到我的两样商品的信息并把得到的两样商品分开保存到数据库中的订单表中
这是通过servlet查询购物车信息的代码
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
HttpSession session=request.getSession();
//得到会员的编号
long cid=(Long)session.getAttribute("cid");
ShopCarManager sm=new ShopCarManagerImp();
ArrayList<ShopCar> s=new ArrayList<ShopCar>();
//通过会员编号去查询购物车
s=sm.select(cid);
session.setAttribute("shopcar", s);
response.sendRedirect("/Shopping/jiemian/showcar.jsp");
}
这是在JSP页面展示购物车信息的代码
<table width="725" border="1" cellpadding="0" cellspacing="0">
<tr><td>商品名</td><td>单价</td><td>数量</td> <td>尺码</td><td>颜色</td> <td>总价</td><td>删除</td></tr>
<%ArrayList<ShopCar> a=(ArrayList<ShopCar>)session.getAttribute("shopcar");
for(int i=0;i<a.size();i++){
ShopCar s=(ShopCar)a.get(i);
%>
<tr><td><%=s.getGoodsName() %></td>
<td><%=s.getGoodsUnitPrice()%></td>
<td> <input type="text" value="<%=s.getBuyNumber() %>" name="number"/></td>
<td></td>
<td></td>
<td><%=s.getGoodsTotalPrice() %></td>
<td><a>删除</a></td></tr>
<% }%>
<tr><td colspan="7">购物车里有商品:1 种 总数:1 件 共计:210 元 您有预存款: 元 </td></tr>
<tr><td colspan="3" align="right"><input type="button" value="修改数量"/></td>
<td colspan="2" align="center"><input type="button" value="清空购物车"/></td>
<td colspan="2"><input type="button" value="结算" onclick="f2.action='jiemian/buyerinfo.jsp';f2.submit()"/></td></tr>
</table>