<%@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>
购物车
最新推荐文章于 2018-04-03 09:32:48 发布