Online book Store Project study notes-017 Checkout, jump checkout page

Source: Internet
Author: User

First, process analysis

Second, the Code

1.view Layer

(1) list.jsp

<tr> <td colspan= "7" align= "right" > <a href= "Javascript:jiesuan ();" Id= "Jiesuan"class= "Jiesuan" ></a> </td> </tr></table> <form id= "Jiesuanform" action= "<c:url VA        Lue= '/cartitemservlet '/> "method=" post "> <input type=" hidden "name=" Cartitemids "id=" Cartitemids "/> <input type= "hidden" name= "Total" id= "Hiddentotal"/> <input type= "hidden" name= "method" Value= "Loadcar Titems "/> </form>/** Settlement*/function Jiesuan () {//1. Get the ID of all selected entries and put them in the arrayvar ids =NewArray (); $("Input[type=checkbox][name=checkboxbtn]:checked"). Each (function (index, Domel) {Ids.push ($ (Domel). Val ());     }); //2. Set the value of the array to ToString (), and then assign the cartitemids of the form to this hidden$ ("#cartItemIds"). Val (IDs); //Save the total value to the form$ ("#hiddenTotal"). Val ($ ("#total"). text ()); //3. Submit this form$ ("#jieSuanForm"). Submit (); }

(2) showitem.jsp

1<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%>2<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>3<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>4 5 6<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >789<title>showitem.jsp</title>Ten      One<meta http-equiv= "Pragma" content= "No-cache" > A<meta http-equiv= "Cache-control" content= "No-cache" > -<meta http-equiv= "Expires" content= "0" > -<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" > the<meta http-equiv= "description" content= "This is my page" > -<!-- -<link rel= "stylesheet" type= "Text/css" href= "Styles.css" > -- +<link rel= "stylesheet" type= "Text/css" href= "<c:url value= '/jsps/css/cart/showitem.css '/>" > -<script src= "<c:url value= '/jquery/jquery-1.5.1.js '/>" ></script> +<script src= "<c:url value= '/js/round.js '/>" ></script> A<style type= "Text/css" > at#addr {width:500px; height:32px;border:1px solid #7f9db9; padding-left:10px; line-height:32px;} -</style> -  -<script type= "Text/javascript" > -     //Calculate Totals - $ (function () { invar total = 0; -$ (". Subtotal"). each (function () { toTotal + = number ($ ( This). text ()); +         }); -         //$ ("#total"). Text (Round (total, 2)); the     }); *</script> $Panax Notoginseng    -<body> the<form id= "Form1" action= "<c:url value= '/jsps/order/ordersucc.jsp '/>" method= "POST" > +<input type= "hidden" name= "Cartitemids" value= "/> A<input type= "hidden" name= "method" Value= "/> the<table width= "95%" align= "center" cellpadding= "0" cellspacing= "0" > +<tr bgcolor= "#efeae5" > -&LT;TD width= "400px" colspan= "5" ><span style= "font-weight:900;" > Generate Orders </span></td> $</tr> $&LT;TR align= "center" > -&LT;TD width= "10%" >&nbsp;</td> -&LT;TD width= "50%" > Book name </td> the<td> Unit Price </td> -<td> Quantity </td>Wuyi<td> Subtotal </td> the</tr> -  Wu  -<c:foreach items= "${items}" var= "Item" > About&LT;TR align= "center" > $&LT;TD align= "Right" > -<aclass= "Linkimage" href= "<c:url value= '/jsps/book/desc.jsp '/>" > '/></a> -</td> -&LT;TD align= "Left" > A<a href= "<c:url value= '/jsps/book/desc.jsp '/>" ><span>${item.book.bname}</span></a> +</td> the<td>&yen;${item.book.currprice}</td> -<td>${item.quantity}</td> $<td> the<spanclass= "Price_n" >&yen;<spanclass= "Subtotal" >${item.subtotal}</span></span> the</td> the</tr> the</c:forEach> -      in<tr> the&LT;TD colspan= "6" align= "right" > the<span> Total: </span><spanclass= "price_t" >&yen;<span id= "Total" >${total}</span></span> About</td> the</tr> the<tr> the&LT;TD colspan= "5" bgcolor= "#efeae5" ><span style= "font-weight:900" > Shipping address </span></td> +</tr> -<tr> the&LT;TD colspan= "6" >Bayi<input id= "addr" type= "text" name= "address" value= "Beijing Changping District xisanqi Xisanqi Office Building 1-layer Preach intelligence podcast Goodbye"/> the</td> the</tr> -<tr> -&LT;TD style= "BORDER-TOP-WIDTH:4PX;" colspan= "5" align= "right" > the<a id= "Linksubmit" href= "javascript:$ (' #form1 '). Submit ();" > Submit Orders </a> the</td> the</tr> the</table> -</form> the</body> the

2.servlet Layer

(1) Cartitemservlet.java

1     /**2 * Load multiple Cartitem3      * @paramreq4      * @paramresp5      * @return6      * @throwsservletexception7      * @throwsIOException8      */9      PublicString Loadcartitems (httpservletrequest req, HttpServletResponse resp)Ten             throwsservletexception, IOException { One         //1. Get the Cartitemids parameter AString ids = Req.getparameter ("Cartitemids"); -         DoubleTotal = double.parsedouble (Req.getparameter ("Total")); -         //2. Get list<cartitem> through the service thelist<cartitem> items =Service.loadcartitems (IDS); -         //3. Save, then forward to/cart/showitem.jsp -Req.setattribute ("Items", items); -Req.setattribute ("Total", total); +Req.setattribute ("Cartitemids", IDS); -         return"F:/jsps/cart/showitem.jsp"; +          A}

3.service Layer

(1) Cartitemservice.java

1     /**2 * Load multiple Cartitem3      * @paramIDs4      * @return5      */6      PublicList<cartitem>Loadcartitems (String IDs) {7         Try {8             returnDao.loadcartitems (IDS);9}Catch(SQLException e) {Ten             Throw NewRuntimeException (e); One         } A}

4.dao Layer

(1) Cartitemdao.java

1     /**2 * Load multiple Cartitem3      * @paramIDs4      * @return5      * @throwsSQLException6      */7      PublicList<cartitem> Loadcartitems (String IDs)throwsSQLException {8String [] Idsarray = Ids.split (",");9String sql = "SELECT * from T_cartitem C, T_book b where c.bid=b.bid and cartitemid in" +Towheresql (idsarray.length);Tenlist<map<string,object>> maplist = qr.query (sql,NewMaplisthandler (), idsarray); One         returntocartitemlist (maplist); A}

Web Book Mall Project study notes-017 Checkout, jump checkout page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.