⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewcart.jsp

📁 jsp/servlet/javaBean应用:网上购书系统
💻 JSP
字号:
<%@ page language="java" session="true" pageEncoding="GBK"%>
<%@ page import="java.util.*,bean.*,java.text.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'viewCart.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		<table align="center">
			<tr>
				<td>
					<%
						Map cart = (Map) session.getAttribute("cart");

						if (cart == null || cart.size() == 0) {
							out.println("<p>购物车当前为空</p>");
						} else {
					%>
					<table border="1" align="center">
						<thead>
							<tr align="center">
								<th>
									名称
								</th>
								<th>
									数量
								</th>
								<th>
									价格
								</th>
								<th>
									小计
								</th>
							</tr>
						</thead>
						<%
								Set cartItems = cart.keySet();
								Object[] isbn = cartItems.toArray();
								double total = 0, price, subtotal;
								int quantity;
								for (int i = 0; i < isbn.length; i++) {
									CartItemBean cartBean = (CartItemBean) cart
									.get((String) isbn[i]);
									BookBean book = cartBean.getBook();
									quantity = cartBean.getQuantity();
									price = book.getPrice();
									subtotal = price * quantity;
									total += subtotal;
						%>
						<tr>
							<td>
								<%=book.getTitle()%>
							</td>
							<td>
								<%=quantity%>
							</td>
							<td>
								<%=new DecimalFormat("0.00").format(price)%>
							</td>
							<td>
								<%=new DecimalFormat("0.00").format(subtotal)%>
							</td>
						</tr>
						<%
						}
						%>
						<tr>
							<td colspan="4" align="right">
								<b>总计:</b>
								<%=new DecimalFormat("0.00").format(total)%>
							</td>
						</tr>
					</table>
					<%
						session.setAttribute("total", new Double(total));
						}
					%>
					<p>
						<a href="chJsp/books.jsp">继续购物</a>
					</p>
					<form method="get" action="chJsp/order.jsp">
						<p>
							<input type="submit" value="结  帐">
						</p>
					</form>
				</td>
			</tr>
		</table>
	</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -