?? showcar.jsp
字號:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@page import="com.hygj.bean.ProductsBean"%>
<%@page import="com.hygj.service.ProductsService"%>
<%
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>購物車顯示頁面</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>
<%
//獲得購物車
Hashtable car=(Hashtable)session.getAttribute("car");
//判斷購物車是否存在
if(car==null){
response.sendRedirect("index.jsp");
}
else{
//判斷購物車中是否有商品信息,內容是否為空
if(car.isEmpty()){
out.print("您的購物車為空,請<a href='index.jsp'>選擇商品</a>后,繼續購買!");
}
else{
//購物車存在,而且有購物信息,進行信息顯示
%>
<center>
您的購物車<br>
<table border="1" cellspacing="0">
<tr><td>商品名稱</td><td>商品單價</td><td>購買數量</td><td>金額</td><td>修改數量</td><td>刪除商品</td></tr>
<%
//從數據庫中獲得商品詳細信息
//獲得 哈希表中的名稱的集合
Enumeration keys=car.keys();
float totalMoney=0.00f;
while(keys.hasMoreElements()){
//獲得具體的商品編號
String productId=(String)keys.nextElement();
//根據名稱獲得具體的值,購買數量
String shuliang=(String)car.get(productId);
//根據商品編號獲得具體的商品信息
ProductsBean product=new ProductsService().getById(Integer.parseInt(productId));
//計算金額
float money=product.getUnitPrice()*Integer.parseInt(shuliang);
totalMoney+=money;
%>
<tr>
<td><%=product.getProductName() %></td>
<td><%=product.getUnitPrice() %></td>
<td><%=shuliang %></td>
<td><%=money %></td>
<td><a href="goumai.jsp?productId=<%=productId %>&shuliang=<%=shuliang %>">修改數量</a></td>
<td><a href="DeleteProduct?productId=<%=productId %>">刪除商品</a></td>
</tr>
<%
}
%>
<tr><td colspan="6">總計:<%=totalMoney %></td></tr>
</table><br>
<a href="index.jsp">繼續購物</a> <a href="DeleteCar">清空購物車</a> <a href="OrderServlet">生成訂單</a>
</center>
<%
}
}
%>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -