cds.jsp~8~

来自「100多M的J2EE培训内容」· JSP~8~ 代码 · 共 66 行

JSP~8~
66
字号
<HTML><HEAD><TITLE>Example of Using Session Scope</TITLE></HEAD><BODY>
<jsp:useBean id="shoppingCart"
     class="shoppingcart.ShoppingCart" scope="session"/>
<%@ page import="shoppingcart.Item" %>
[ Shop for CDs ] <A HREF="toys.jsp">Shop for Toys</A>
<H1> Online CD Catalog </H1>
<TABLE>
<TR><TD BGCOLOR=AAAAAA ALIGN=CENTER>Name</TD><TD BGCOLOR=AAAAAA>SKU</TD>
    <TD BGCOLOR=AAAAAA>Decription</TD><TD BGCOLOR=AAAAAA>Price</TD>
    <TD BGCOLOR=AAAAAA>&nbsp;</TD></TR>
<% String[] names = {"Tchaikovsky","Mendelssohn","Haydn","Schumann","Bach"};
   String[] SKUs  = {"A111","2B22","33C3","444D","E555"};
   double[] prices = {12.00, 23.50, 34.00, 45.50, 56.00};
   int Quantity=1;
   for(int j=0; j<names.length; j++){ %>
     <TR><TD BGCOLOR=DDDDDD><%=names[j]%>  </TD>
         <TD BGCOLOR=DDDDDD><%=SKUs[j]%>   </TD>
         <TD BGCOLOR=DDDDDD>Music CD       </TD>
         <TD BGCOLOR=DDDDDD><%=Quantity%>   </TD>
         <TD BGCOLOR=DDDDDD><%=prices[j]%>0</TD>
         <TD BGCOLOR=DDDDDD>
             <A HREF="cds.jsp?name=<%=names[j]%>&sku=<%=SKUs[j]%>&quantity=<%=Quantity%>&price=<%=prices[j]%>">
              Add</A></TD></TR>
<% } %>
</TABLE>
<A HREF=cds.jsp?name=emptyCart>Empty Shopping Cart</A>
<HR>
<H1> Content of Shopping Cart </H1>
<% String name = request.getParameter("name");
   if(name!=null){
     if(name.equals("emptyCart")){
       shoppingCart.emptyCart();
     } else if(name.equals("deleteItem")) {
       String sku = request.getParameter("sku");
       shoppingCart.deleteItem(sku);
     } else {
       String sku = request.getParameter("sku");
       double price = Double.parseDouble(request.getParameter("price"));
       int quantity=1;
       Item newItem = new Item(sku, name, "Music CD", quantity,price);
       shoppingCart.addItem(newItem);
   }} %>
<TABLE>
<TR><TD BGCOLOR=AAAAAA ALIGN=CENTER>Name</TD><TD BGCOLOR=AAAAAA>SKU</TD>
    <TD BGCOLOR=AAAAAA>Decription</TD>
    <TD BGCOLOR=AAAAAA>Quantity</TD>
    <TD BGCOLOR=AAAAAA ALIGN=CENTER>Price</TD><TD BGCOLOR=AAAAAA>&nbsp;</TD>
    </TR>
<% java.util.Enumeration items = shoppingCart.getItems();
   while(items.hasMoreElements()){
     Item item = (Item)items.nextElement(); %>
     <TR><TD BGCOLOR=DDDDDD><%=item.getName()%>              </TD>
         <TD BGCOLOR=DDDDDD><%=item.getSku()%>               </TD>
         <TD BGCOLOR=DDDDDD><%=item.getDescription()%>       </TD>
         <TD BGCOLOR=DDDDDD><%=item.getQuantity()%>          </TD>
         <TD BGCOLOR=DDDDDD ALIGN=RIGHT><%=item.getPrice()%>0</TD>

         <TD BGCOLOR=DDDDDD>
             <A HREF="cds.jsp?name=deleteItem&sku=<%=item.getSku()%>">
             Remove</A></TD>
<% }
   double total = shoppingCart.computeTotal(); %>
     <TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD BGCOLOR="DDDDDD">Total</TD>
     <TD BGCOLOR=DDDDDD ALIGN=RIGHT><%=shoppingCart.computeTotal()%>0
     </TD></TR>
</TABLE></BODY></HTML>

⌨️ 快捷键说明

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