⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoppingcart.jsp

📁 a JSP page of shopping cart
💻 JSP
字号:
<%@ include file="Common.jsp" %>

<jsp:useBean id="cart" scope="session" class="ShoppingCart" />


<%

/*
ShoppingCart cart=(ShoppingCart)session.getAttribute("cart");
if (cart==null) {   
 cart=new ShoppingCart();
 session.setAttribute("cart",cart); 
}
*/


String sCartAction=(String) getParam(request,"cartAction");

if (sCartAction.equals("addnew")){
   String item_id=getParam(request,"item_id");
   String item_desc=getParam(request,"item_desc");
   float item_price=Float.parseFloat(getParam(request,"item_price"));   
   cart.addItem(item_id,item_desc,item_price,1);  
}

if (sCartAction.equals("delete")){
   cart.removeItem(getParam(request,"item_id"));
}

if (sCartAction.equals("clear")){
   cart.clearItems();
}


if (sCartAction.equals("update")){

   
   
    String itemList[]=request.getParameterValues("item_id");
    String qtyList[]=request.getParameterValues("itemQty");
    
    if  (itemList!=null) {
       if (itemList.length==1) {
                  int qty=Integer.parseInt(qtyList[0]);   
                  cart.updateQuantity(itemList[0],qty);                                 
       }
       else {
          for (int i=0; i<itemList.length; i++){
              try{
                   int qty=Integer.parseInt(qtyList[i]);   
                  cart.updateQuantity(itemList[i],qty);                                 
              }catch (Exception e){}
          }             
       }
   }

}

%>


<html>
<head>
<title>Book Store</title>
<meta name="GENERATOR" content="YesSoftware CodeCharge v.1.2.0 / JSP.ccp build 05/21/2001"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>

<body style="background-color: #FFFFFF; color: #000000; font-family: Arial, Tahoma, Verdana, Helveticabackground-color: #FFFFFF; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
<jsp:include page="Header.jsp" flush="true"/>

<form name=frm method=post>
 <table>
     <!-- Show cart content here  -->
     <!-- First Header   -->
     <tr>
         <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00; font-weight: bold">Name</font></td>
         <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00; font-weight: bold">Price</font></td>   
         <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00; font-weight: bold">Qty</font></td>
         <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00; font-weight: bold">Sub total</font></td>
         <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00; font-weight: bold">Remove</font></td>
         
     <tr> 
     
     <!-- Then content   -->
    <%
  
     
    java.util.Enumeration  itemsEnum = cart.getEnumeration();
    String[] tmpItem;
    float totalCost=cart.getCost();
    
    while ( itemsEnum.hasMoreElements() ) {
           tmpItem = (String[])itemsEnum.nextElement();
           totalCost += (Integer.parseInt(tmpItem[3]) * Float.parseFloat(tmpItem[2]));
           float   subTotal=Integer.parseInt(tmpItem[3]) * Float.parseFloat(tmpItem[2]);
           String flditem_id = tmpItem[0];;
           String flditem_name = tmpItem[1];
           String fldprice = tmpItem[2];
           String fldquantity = tmpItem[3];
           
    %>
    <tr>
    <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00;"><a href=BookDetail.jsp?item_id=<%=flditem_id%>><%=flditem_name%></font></td>
    <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00;"><%=toHTML(fldprice)%></font></td>   
    <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00;"><input type=text name=itemQty  value='<%=toHTML(fldquantity)%>' style='width:50'></font></td>                                                                                                                                                          
    <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00; "><%=Float.toString(subTotal)%></font></td>
    <td colspan=1 style=background-color: #FFFFFF; border-style: inset; border-width: 0"><font style="font-size: 10pt; color: #CE7E00;"> <a href=ShoppingCart.jsp?item_id=<%=flditem_id%>&cartAction=delete> delete </a></font></td>
     <input type=hidden name=item_id value=<%=flditem_id%> >    
    </tr>  
    
  <%
   }
  %>
    
  </table> <p>
      
  <input type=button value='Update Selected' onclick='doAction(this)'>
  <input type=button value='Clear Basket' onclick='doAction(this)'>
  <input type=button value='Check out' onclick='doAction(this)'> 
  <input type=button value='Continue Shopping' onclick='doAction(this)'> 
  
 </form>
 
 
 <script language=javascript>
    function doAction(button){
       if (button.value=="Continue Shopping"){
          window.open("Default.jsp","_parent");           
       }
       
       if (button.value=="Update Selected"){          
          frm.action="ShoppingCart.jsp?cartAction=update";          
          frm.submit();          
       }
       
       if (button.value=="Clear Basket"){
          frm.action="ShoppingCart.jsp?cartAction=clear";
          frm.submit();       
       }

       if (button.value=="Check out"){
          frm.action="CheckOut.jsp";
          frm.submit();                     
       }
       
    }
 </script>
  
 </table>


<jsp:include page="Footer.jsp" flush="true"/>

</body>
</html>

⌨️ 快捷键说明

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