购物车

<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="com.lovo.entity.BookBeen"%>
<%@page import="com.lovo.server.IBookServer"%>
<%@page import="com.lovo.server.impl.BookServerImpl"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<!-- <a href="showShop.jsp">返回</a> -->

<% 
    String id = request.getParameter("id");
    IBookServer ibs = new BookServerImpl();
    int idNew = Integer.parseInt(id);
    /* 获取要购买的book */

    /* 获取Session对象 */
    HttpSession s = request.getSession();
    Map<Integer, Integer> shopCar;
    if(s.getAttribute("shopCar") == null){
        shopCar = new HashMap<Integer, Integer>();
        s.setAttribute("shopCar", shopCar);
    }
    /* 得到购物车 */
    shopCar = (Map<Integer, Integer>)s.getAttribute("shopCar");
    if(shopCar == null){
        /* 如果用户从未购物,则为其创建购物车 */
        shopCar = new HashMap<Integer, Integer>();
    }

    /* 判断购物车是否有该book,若有+1;没有则数量设为1 */
    /* 在购物车中查找该id */
    if(shopCar.get(idNew) == null){
        shopCar.put(idNew, 1);
    }else{
        shopCar.put(idNew, shopCar.get(idNew)+1);
    }
    s.setAttribute("shopCar", shopCar);

%>



<a href="showCar.jsp">查看购物车</a>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值