?? viewcart.jsp
字號:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import = "Entities.*" %>
<%@ page import = "java.text.*" %>
<%
Map cart = (Map) session.getAttribute("cart");
double total = 0;
if(cart == null || cart.size() == 0)
{
out.println("<p>購物車當前為空</p>");
}
else
{
//創建用于顯示內容的變量
Set cartItems = cart.keySet();//先得到Map中key的set集合
Object[] ID = cartItems.toArray();//將set集合轉換成數組
FoodBean food;
CartItemBean cartItem;
int quantity;
double price,subtotal;
%>
<html>
<head>
<title>購物車</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="./css/styles.css" type="text/css" />
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
text="#000000" link="#000000" vlink="#000000" alink="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
bgcolor="#FFFFFF" height="100%">
<tr valign="top">
<td>
<table width="98%" border="0" cellspacing="1" cellpadding="2"
align="center">
<tr valign="bottom">
<td height="30"><img
src="http://i-560.wz8.cn/pic1/shop/cart.gif"> <font
color="#000000">您的購物車中有以下商品</font></td>
</tr>
</table>
<table width="98%" border="0" cellspacing="2" cellpadding="0"
align="center">
<tr bgcolor=#808000>
<td height="1" bgcolor="#999999"></td>
</tr>
</table>
<table width="98%" border="0" cellspacing="2" cellpadding="0"
align="center">
<tr>
<td height="5"></td>
</tr>
</table>
<table width="98%" border="0" cellspacing="0" cellpadding="0"
align="center">
<tr>
<td>
<table width="100%" border="0" align="CENTER" cellpadding="2"
cellspacing="1" bgcolor="#c0c0c0">
<tr bgcolor="#dadada">
<td height="22" width="50">
<div align="CENTER"><font color="#000000">編號</font></div>
</td>
<td width="610" height="22">
<div align="CENTER"><font color="#000000">商品名稱</font></div>
</td>
<td height="22" width="104">
<div align="CENTER"><font color="#000000">單價</font></div>
</td>
<td height="22" width="100">
<div align="CENTER"><font color="#000000">數量</font></div>
</td>
<td width="116" height="22">
<div align="CENTER"><font color="#000000">金額</font></div>
</td>
</tr>
<%
int i = 0;
while(i < ID.length )
{
//計算總和
cartItem = (CartItemBean) cart.get(ID[i]);
food = cartItem.getFood();
quantity = cartItem.getQuantity();
price = food.getFoodPrice();
subtotal = quantity*price;
total +=subtotal;
i ++;
%>
<tr bgcolor="#ffffff">
<td width="50" align="center" height="22"><font
color="#000000"><%=food.getFoodID() %></font></td>
<td align="center" height="22"><font color="#000000"><%=food.getFoodName() %></font>
<input type="hidden" name="prodid" value="500047"></td>
<td width="104" align="center" height="22"><font
color="#000000">¥<%=new DecimalFormat("0.00").format(food.getFoodPrice()) %></font></td>
<td width="100" class="hh" align="center" height="22"><%=quantity %></td>
<td width="116" class="bb" align="center" height="22"><font
color="#000000">¥<%=new DecimalFormat("0.00").format(subtotal)%></font></td>
</tr>
<%}
%>
<tr bgcolor="#dadada">
<td width="50" height="22" align="center"><font
color="#000000">合計</font></td>
<td height="22" align="center"><font color="#000000">-</font></td>
<td width="104" height="22" align="center"><font
color="#000000">-</font></td>
<td width="100" class="hh" height="22" align="center"><font
color="#000000">-</font></td>
<td width="116" class="bb" align="center" height="22"><font
color="#000000">¥<%=total %></font></td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="1" cellpadding="4"
align="CENTER" bgcolor="#c0c0c0">
<tr bgcolor="#dadada">
<td height="10" align="center"><a href="#"><font
color="#000000">清空購物車</font></a></td>
<td height="10" align="center" style="cursor:hand" onClick="#"><font
color="#000000"><a href ="show.jsp">繼續購物</a></font></td>
<td height="10" align="center" style="cursor:hand" onClick="#"><font
color="#000000"><a href="checkOut.html">生成訂單</a></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
session.setAttribute("total",new Double(total));
}
%>
<br>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -