Java Reference
In-Depth Information
<BR><BR><BR>
<H1><P STYLE="color:red">Order List</P></H1>
<BR><BR><BR>
<TABLE>
<TR>
<TH>Item</TH>
<TH>Weight(kg)</TH>
<TH>Cost(£)</TH>
</TR>
<!-- Now make use of the implicit object session -->
<!-- to retrieve the contents of the shopping cart… -->
<%
session.removeAttribute("currentProd");
//(Removes "Checkout".)
Enumeration prodNames = session.getAttributeNames();
fl oat totalCost = 0;
int numProducts = 0;
while (prodNames.hasMoreElements())
{
fl oat wt=0,cost=0;
String product = (String)prodNames.nextElement();
String stringWt =
(String)session.getAttribute(product);
wt = Float.parseFloat(stringWt);
if (product.equals("Apples"))
cost = APPLES_PRICE * wt;
else if (product.equals("Pears"))
cost = PEARS_PRICE * wt;
%>
<TR>
<TD> <%= product %> </TD>
<TD> <%= wt %> </TD>
<TD> <%= String.format("%.2f",cost) %> </TD>
</TR>
<%
totalCost+=cost;
numProducts++;
}
%>
<TR STYLE="background-color:yellow">
<%
if (numProducts == 0)
{
Search WWH ::




Custom Search