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

📄 cart.jsp

📁 用java编写的程序
💻 JSP
字号:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="webbook.shopping.cart.*,java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>display cart page</title>
</head>
<body>
<%
pageContext.setAttribute("rootPath",request.getContextPath());
ShoppingCart cart=(ShoppingCart)session.getAttribute("shoppingcart");
if (cart == null) {
	cart = new ShoppingCart();
	session.setAttribute("shoppingcart", cart);
}

ArrayList items=cart.getCart();
if (items.size() == 0) { 
%>
<H1>您的购物车为空</H1><BR>
<a href="${rootPath}/displayitems.jsp">浏览商品,添加商品到购物车</a><BR>
<%
} else { 
%>
<H1>显示购物车的内容</H1><BR>
<a href="${rootPath}/displayitems.jsp">继续浏览商品,添加商品到购物车</a><BR>
<a href="${rootPath}/servlet/shoppingCart?method=clear">清空购物车</a><BR>

<table width="600" border="1" align="left">
  <tr>
    <td width="200">商品名称</td>
    <td width="50">价格</td>
    <td width="50">数量</td>
    <td width="100">小计</td>
    <td width="100">操作</td>
  </tr>
<%
	for (int i = 0; i < items.size(); i++) {
	CartItem item = (CartItem) items.get(i);
	pageContext.setAttribute("item",item);
 %>  
  <form  name="form" method="post" action="/shoppingcart2/servlet/shoppingCart">
  <tr>
    <td>${item.name}</td>
    <td>${item.price}元</td>	
	<input type="hidden" name="id" value="${item.id}">
    <td><input name="q" type="text" value="${item.quantity}" size="4" maxlength="4"></td>
    <td>${item.sum}元</td>	
    <td><input type="submit" name="method" value="update" >
      <input type="submit" name="method" value="remove" ></td>
  </tr>
  </form>   
  <% }%>
  <tr>
    <td colspan="5">总计:<%=cart.getTotal()%>元</td>
  </tr>
</table>
<% }%>
</body>
</html>



		





⌨️ 快捷键说明

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