Java中的清除购物车按钮

时间:2014-12-29 07:59:43

标签: java html css jsp project

您好我正在尝试在我的java代码中创建一个“清除购物车”按钮,但我遇到了困难。 我已经尝试了几个小时,但我无法让它工作

我认为它主要涉及具有所有字符串和变量的第一部分。

以下是代码:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ page errorPage="errorpage.jsp" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>the Game Store</title>
    </head>
    <body>
<%
    String id = request.getParameter("id");
    if ( id != null ) {
      String desc = request.getParameter("desc");

      Float price = new Float(request.getParameter("price"));

      cart.addItem(id, desc, price.floatValue(), 1);

    }
  %>
  <a href="ShoppingCart.jsp">Shopping Cart Quantity:</a>
    <%=cart.getNumOfItems() %>
  <hr>
  <center><h3>Games</h3></center>
  <table border="1" width="300" cellspacing="0"
  cellpadding="2" align="center">
    <tr><th>Description</th><th>Price</th></tr>
    <tr>
      <form action="AddToShoppingCart.jsp" method="post">
        <td>Goat Simulator</td>
        <td>$11.95</td>
        <td><input type="submit" name="Submit" value="Add"></td>
        <input type="hidden" name="id" value="1">
        <input type="hidden" name="desc" value="Goat Simulator">
        <input type="hidden" name="price" value="11.95">
      </form>
    </tr>
    <tr>
      <form action="AddToShoppingCart.jsp" method="post">
        <td>Metal Gear Solid V</td>
        <td>$59.99</td>
        <td><input type="submit" name="Submit" value="Add"></td>
        <input type="hidden" name="id" value="2">
        <input type="hidden" name="desc" value="Metal Gear Solid V">
        <input type="hidden" name="price" value="59.99">
      </form>
    </tr>

     <tr>
      <form action="AddToShoppingCart.jsp" method="post">
        <input type ="submit" name="empty" id="empty-button" value="Empty Cart"/>
      </form>
      <a href="AddToShoppingCart.jsp">Clear</a>

    </tr>

    </table>
  </body>
</html>

这是整个页面的第二页

<%@ page errorPage="errorpage.jsp" %>
<%@ page import="java.util.*" %>

<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <title>Shopping Cart Contents</title>
  </head>
  <body>
    <center>
    <table width="300" border="1" cellspacing="0"
      cellpadding="2" border="0">
      <caption><b>Shopping Cart Contents</b></caption>
      <tr>
        <th>Description</th>
        <th>Price</th>
        <th>Quantity</th>
      </tr>
    <%
      Enumeration e = cart.getEnumeration();
      String[] tmpItem;
      // Iterate over the cart
      while (e.hasMoreElements()) {
        tmpItem = (String[])e.nextElement();
        %>
        <tr>
          <td><%=tmpItem[1] %></td>
          <td align="center">$<%=tmpItem[2] %></td>
          <td align="center"><%=tmpItem[3] %></td>
        </tr>
        <%
      }
    %> 
    </table>
    </center>
    <a href="AddToShoppingCart.jsp">Back to Catalog</a>
  </body>
</html>

0 个答案:

没有答案