Codice completo

Listato 4. Servlet cart.jsp

<%@ page import="java.util.*,it.html.shop.*,it.html.ejb.session.stateful.ShoppingCart" language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Carrello della spesa</title>
</head>
<body>
<h1>Lista carrello della spesa</h1>
<table>
  <tr>
    <th>ID</th>
    <th>Titolo</th>
    <th>Prezzo (Eu)</th>
  </tr>
  <%
    ShoppingCart cart=(ShoppingCart)request.getAttribute("cart");
    Iterator it=cart.getList().iterator();
    while (it.hasNext()){
      Product tmp=(Product)it.next();
      %>
      <tr>
        <td><%=tmp.getId()%></td>
        <td><%=tmp.getTitle()%></td>
        <td><%=tmp.getCost()%></td>
      </tr>
      <%
    }
  %>
  
</table>

<p>Il costo totale è <b><%=cart.totalAmount()%></b> Euro.</p>

</body>
</html>