Java?web實現(xiàn)購物車案例
本文實例為大家分享了Java web實現(xiàn)購物車的具體實現(xiàn)代碼,供大家參考,具體內容如下
一. 簡介:
本項目使用jsp,js,Java,html,css,EL表達式,JSTL所實現(xiàn)
使用編輯器:idea
使用Oracle數(shù)據(jù)庫
新增:
EL表達式
JSTL標簽庫
二. 前臺
1.包括用戶注冊,登錄
Html +js+jsp
效果展示

<body>
<div class="jq22-container" style="padding-top:100px">
? ? <div class="login-wrap">
? ? ? ? <div class="login-html">
? ? ? ? ? ? <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">登錄</label>
? ? ? ? ? ? <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">注冊</label>
? ? ? ? ? ? <div class="login-form">
? ? ? ? ? ? ? ? <div class="sign-in-htm">
? ? ? ? ? ? ? ? ? ? <form action="${pageContext.request.contextPath }/LoginServlet.do" method="post" onsubmit="return checkAll()">
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="user1" class="label">賬號</label>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input name="uname" id="uname" type="text" class="input">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="upwd" class="label">密碼</label>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input name="upwd" id="upwd" type="password" class="input" data-type="password">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="check" type="checkbox" class="check">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="check"><span class="icon"></span>自動登錄</label>
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input type="submit" class="button" value="登錄">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? </form>
? ? ? ? ? ? ? ? ? ? <div class="hr"></div>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div class="sign-up-htm">
? ? ? ? ? ? ? ? ? ? <form action="${pageContext.request.contextPath }/registerServlet.do" method="post">
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="user1" class="label">賬號</label>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="user1" type="text" class="input">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="upwd" class="label">密碼</label>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="upwd1" type="password" class="input" data-type="password">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="pass3" class="label">確認密碼</label>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="pass3" type="password" class="input" data-type="password">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="group">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input type="submit" class="button" value="注冊">
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="hr"></div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="foot-lnk">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label for="tab-1"></label>
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? </form>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? </div>
? ? </div>
</div>
</body>2.主界面(效果圖);
使用了List集合保存數(shù)據(jù)并綁定頁面

<body>
<div class="container">
? ? <h3 style="text-align: center">商城列表</h3>
? ? ? ? ? ? <form>
? ? ? ? ? ? ? ? <table border="1" class="table table-bordered table-hover">
? ? ? ? ? ? ? ? ? ? <tr class="success">
? ? ? ? ? ? ? ? ? ? ? ? <th>商品序號</th>
? ? ? ? ? ? ? ? ? ? ? ? <th>商品名稱</th>
? ? ? ? ? ? ? ? ? ? ? ? <th>商品價格</th>
? ? ? ? ? ? ? ? ? ? ? ? <th>商品描述</th>
? ? ? ? ? ? ? ? ? ? ? ? <th>商品圖片</th>
? ? ? ? ? ? ? ? ? ? ? ? <th>操作</th>
? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? <c:forEach var="good" items="goods">
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>${good.gid()}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>${good.gname()}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>${good.gprice()}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>${good.ginfo()}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td><img src="../static/${good.gpath()}"></td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath }/goodsServlet.do?nid=${good.gid()}" >購買</a> </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? </c:forEach>
? ? ? ? ? ? ? ? </table>
? ? ? ? ? ? </form>
</div>
</body>3.購物車(效果圖):
使用了session保存數(shù)據(jù)從主界面?zhèn)鲄?shù)

這是jsp代碼,里面加入了EL表達式和jstl
<body>
<div class="container">
? ? <h3 style="text-align: center">購物車列表</h3>
? ? <table border="1" class="table table-bordered table-hover">
? ? ? ? <tr class="success">
? ? ? ? ? ? <th><input type="checkbox" id="chElt" onclick="checkOrCancelAll()"><span id="mySpan"></span></th>
? ? ? ? ? ? <th>商品序號</th>
? ? ? ? ? ? <th>商品名稱</th>
? ? ? ? ? ? <th>商品描述</th>
? ? ? ? ? ? <th>商品圖片</th>
? ? ? ? ? ? <th>商品數(shù)量</th>
? ? ? ? ? ? <th>商品總價</th>
? ? ? ? ? ? <th>操作</th>
? ? ? ? </tr>
? ? ? ? <c:forEach var="s" items="listshopping">
? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? <td><input type="checkbox" class="interest"></td>
? ? ? ? ? ? ? ? <td>${s.Sid()}</td>
? ? ? ? ? ? ? ? <td>${s.Sname()}</td>
? ? ? ? ? ? ? ? <td>${s.Sinfo()}</td>
? ? ? ? ? ? ? ? <td><img src="../static/${s.Spath()}"></td>
? ? ? ? ? ? ? ? <input id="${s.Sid()}" style="width: 40px;text-align: center;" type="text" value="${s.Count()}"/>
? ? ? ? ? ? ? ? <td>總價錢</td>
? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath }/goodsServlet.do" >購買</a> 
? ? ? ? ? ? ? ? ? ? <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath }/shoppingServlet.do?nid=${s.Sid()}" >刪除</a>
? ? ? ? ? ? ? ? ? ? <a class="btn btn-default btn-sm" href="/updateOrder.do?nid=${s.Sid()}" >修改</a>
? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? </tr>
? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? <td colspan="8" align="left"><a href="${pageContext.request.contextPath }/admin/xmb.jsp" >返回商品頁面</a></td>
? ? ? ? ? ? ? ? <td colspan="8" align="right"><a href="${pageContext.request.contextPath }/closeServlet.do?nid=${s.Sid()}" >我要結賬</a></td>
? ? ? ? ? ? </tr>
? ? ? ? </c:forEach>
? ? </table>
</div>
</body>以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Java實現(xiàn)的質因數(shù)分解操作示例【基于遞歸算法】
這篇文章主要介紹了Java實現(xiàn)的質因數(shù)分解操作,結合實例形式較為詳細的分析了Java基于遞歸算法實現(xiàn)針對整數(shù)的質因數(shù)分解相關操作技巧,需要的朋友可以參考下2018-03-03
startJVM錯誤Unable to load native library: libjvm.so解決方法
這篇文章主要介紹了startJVM錯誤Unable to load native library: libjvm.so解決方法,需要的朋友可以參考下2014-07-07
MybatisPlus 多租戶架構(Multi-tenancy)實現(xiàn)詳解
這篇文章主要介紹了MybatisPlus 多租戶架構(Multi-tenancy)實現(xiàn)詳解,詳細的介紹了什么是多租戶架構以及使用MybatisPlus實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11
SpringBoot中實現(xiàn)訂單30分鐘自動取消的項目實踐
現(xiàn)在電子商務平臺上訂單創(chuàng)建成功,等待支付,一般會給30分鐘的時間,本文主要介紹了SpringBoot中實現(xiàn)訂單30分鐘自動取消的項目實踐,具有一定的參考價值,感興趣的可以了解一下2023-10-10
springboot接入cachecloud redis示例實踐
這篇文章主要介紹了springboot接入cachecloud redis示例實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10

