Map cart = (Map) session.getAttribute("cart");
double total = 0;
if (cart == null || cart.size() == 0)
out.println("<p>购物车当前为空.</p>");
else {
//得到entryset 包含 key 和 value
Set entSet = cart.entrySet();
//得到迭代器 泛型
Iterator<Map.Entry<String,CartItemBean>> it = entSet.iterator();
BookBean book;
CartItemBean cartItem;
int quantity;
double price, subtotal;
int i = 0;
while (it.hasNext()) {
Map.Entry<String,CartItemBean> cartItm = it.next();
// 计算总和
book = cartItm.getValue().getBook();
quantity = cartItm.getValue().getQuantity();
price = book.getPrice();
subtotal = quantity * price;
total += subtotal;
i++;
}
}