cds.jsp~4~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:3k
源码类别:
Java编程
开发平台:
Java
- <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> </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};
- 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><%=prices[j]%>0</TD>
- <TD BGCOLOR=DDDDDD>
- <A HREF="cds.jsp?name=<%=names[j]%>&sku=<%=SKUs[j]%>&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"));
- Item newItem = new Item(sku, name, "Music CD", 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 ALIGN=CENTER>Price</TD><TD BGCOLOR=AAAAAA> </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.getDescription()%> </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> </TD><TD> </TD><TD BGCOLOR="DDDDDD">Total</TD>
- <TD BGCOLOR=DDDDDD ALIGN=RIGHT><%=shoppingCart.computeTotal()%>0
- </TD></TR>
- </TABLE></BODY></HTML>