Java?web實現(xiàn)購物車案例
本文實例為大家分享了Java web實現(xiàn)購物車的具體實現(xiàn)代碼,供大家參考,具體內(nèi)容如下
一. 簡介:
本項目使用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()}" >我要結(jié)賬</a></td>
? ? ? ? ? ? </tr>
? ? ? ? </c:forEach>
? ? </table>
</div>
</body>以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java Web開發(fā)防止多用戶重復登錄的完美解決方案
在web項目開發(fā)中,很多情況下都可以讓同一個賬號信息在不同的登錄入口登錄很多次,這樣子做的不是很完善。一般解決這種情況有兩種解決方案,小編呢主要以第二種方式給大家介紹具體的實現(xiàn)方法,對java web 防止多用戶重復登錄的解決方案感興趣的朋友一起看看吧2016-11-11
Java框架解說之BIO NIO AIO不同IO模型演進之路
網(wǎng)上很多IO資料,對新手來說,越看越暈。根據(jù)自己的理解,總結(jié)對比了一下BIO、NIO、AIO,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-10-10

