JAVA WEB 中间件为SERVLET(五)
寫一個(gè)簡(jiǎn)單的商城
1.登錄系統(tǒng)
2.選擇商品
? ? ? ? 2.1選擇的商品會(huì)存放在數(shù)據(jù)庫(kù)
3.購(gòu)物車結(jié)算
? ? ? ? 3.1可以擴(kuò)展一下,不同的用戶登錄后查看自己加入到購(gòu)物車的商品
登錄頁(yè)面上一章已經(jīng)有了,接下來(lái)就是2個(gè)JSP頁(yè)面分別是商品頁(yè)和購(gòu)物車頁(yè)
商品頁(yè)模板
?購(gòu)物車模板
商品頁(yè)缺少一個(gè)導(dǎo)航欄,用來(lái)實(shí)現(xiàn)商品頁(yè)面和購(gòu)物車頁(yè)面的跳轉(zhuǎn)
jsp頁(yè)面之間的跳轉(zhuǎn)方法
我用的是<a></a>標(biāo)簽,網(wǎng)上有很多方法。這里注意的地方是jsp和jsp通過(guò)<a></a>標(biāo)簽跳轉(zhuǎn)樣式會(huì)失效。處理方法就是用絕對(duì)路徑
這個(gè)就是絕對(duì)路徑
?
我在這里卡了很久,應(yīng)為我的項(xiàng)目名稱和發(fā)布的名稱不同
HTML
表格自動(dòng)添加序號(hào)
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>自動(dòng)編號(hào)</title> </head><script language="javascript" type="text/javascript">window.onload = function () {var tableLine = document.getElementById("number");for (var i = 0; i < tableLine.rows.length; i++) {tableLine.rows[i].cells[0].innerHTML = (i + 1);}} </script> <body><table><tr><td>編號(hào)</td><td>內(nèi)容</td></tr><tbody id="number"><tr><td></td><td>一</td></tr><tr><td></td><td>二</td></tr><tr><td></td><td>三</td></tr></tbody> </table></body> </html>最終展示
附上源碼
<%--Created by IntelliJ IDEA.User: JIAHANGDate: 2023/1/30Time: 16:34To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>購(gòu)物頁(yè)</title><link rel="stylesheet" href="/untitled01_war_exploded/css/product.css" /><script type="text/javascript" src="/untitled01_war_exploded/js/product.js"></script><script type="text/javascript">window.onload = function () {var tableLine = document.getElementById("number");for (var i = 0; i < tableLine.rows.length; i++) {tableLine.rows[i].cells[0].innerHTML = (i + 1);}}</script> </head> <body> <%--<%@include file="/JSP/Navbar.jsp"%>--%> <div class="foot" id="foot"> <%-- <label class="fl select-all"><input type="checkbox" class="check-all check"/> 全選</label>--%> <%-- <a class="fl delete" id="deleeAll" href="././JSP/Shopping.jsp">購(gòu)物車</a>--%><div class="fr closing" ><a class="fr closing" id="#" href="/untitled01_war_exploded/index.jsp">退出</a></div><div class="fr total"><span id="priceTotal"></span></div><div class="fr selected" id="selected"> <%-- <span id="selectedTotal">0</span>件--%> <%-- <span class="arrow up">︽</span>--%> <%-- <span class="arrow down">︾</span>--%><a class="fl delete" id="deleeAll" href="/untitled01_war_exploded/JSP/Shopping.jsp">購(gòu)物車</a></div><div class="selected-view"><div id="selectedViewList" class="clearfix"><!--<div><img src="images/1.jpg"><span>取消選擇</span></div>--></div><span class="arrow">◆<span>◆</span></span></div> </div> <table id="cartTable"><thead><tr><th>序號(hào)</th><th>商品</th><th>單價(jià)</th><th>詳情</th><th>操作</th></tr></thead><tbody id="number"><tr><td class="checkbox"></td><td class="goods"><img src="/untitled01_war_exploded/images/1-1.jpg" alt="" /><span>Casio/卡西歐 EX-TR350</span></td><td class="price">5999.88</td><td class="count">D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run[2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to startUsing CATALINA_BASE: "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\Using CATALINA_HOME: "D:\TOMCAT\apache-tomcat-8.5.85"Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"</td><td class="operation"><span class="delete">加入購(gòu)物車</span></td></tr><tr><td class="checkbox"></td><td class="goods"><img src="/untitled01_war_exploded/images/1-2.jpg" alt="" /><span>Canon/佳能 PowerShot SX50 HS</span></td><td class="price">3888.50</td><td class="count">D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run[2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to startUsing CATALINA_BASE: "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\Using CATALINA_HOME: "D:\TOMCAT\apache-tomcat-8.5.85"Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"</td><td class="operation"><span class="delete">加入購(gòu)物車</span></td></tr><tr><td class="checkbox"></td><td class="goods"><img src="/untitled01_war_exploded/images/1-3.jpg" alt="" /><span>Sony/索尼 DSC-WX300</span></td><td class="price">1428.50</td><td class="count">D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run[2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to startUsing CATALINA_BASE: "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\Using CATALINA_HOME: "D:\TOMCAT\apache-tomcat-8.5.85"Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"</td><td class="operation"><span class="delete">加入購(gòu)物車</span></td></tr><tr><td class="checkbox"></td><td class="goods"><img src="/untitled01_war_exploded/images/1-4.jpg" alt="" /><span>Fujifilm/富士 instax mini 25</span></td><td class="price">640.60</td><td class="count">D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run[2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to startUsing CATALINA_BASE: "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\Using CATALINA_HOME: "D:\TOMCAT\apache-tomcat-8.5.85"Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"</td><td class="operation"><span class="delete">加入購(gòu)物車</span></td></tr></tbody> </table> <%--<a href="././JSP/Shopping.jsp">購(gòu)物車</a>--%></body></html> <%--Created by IntelliJ IDEA.User: JIAHANGDate: 2023/1/30Time: 16:34To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>購(gòu)物頁(yè)</title><link rel="stylesheet" href="/untitled01_war_exploded/css/shopp.css" /><script type="text/javascript" src="/untitled01_war_exploded/js/shopp.js"></script> </head> <body> <table id="cartTable"><thead><tr><th><label><input class="check-all check" type="checkbox"/> 全選</label></th><th>商品</th><th>單價(jià)</th><th>數(shù)量</th><th>小計(jì)</th><th>操作</th></tr></thead><tbody><tr><td class="checkbox"><input class="check-one check" type="checkbox" /></td><td class="goods"><img src="/untitled01_war_exploded/images/1-1.jpg" alt="" /><span>Casio/卡西歐 EX-TR350</span></td><td class="price">5999.88</td><td class="count"><span class="reduce"></span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">5999.88</td><td class="operation"><span class="delete">刪除</span></td></tr><tr><td class="checkbox"><input class="check-one check" type="checkbox" /></td><td class="goods"><img src="/untitled01_war_exploded/images/1-2.jpg" alt="" /><span>Canon/佳能 PowerShot SX50 HS</span></td><td class="price">3888.50</td><td class="count"><span class="reduce"></span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">3888.50</td><td class="operation"><span class="delete">刪除</span></td></tr><tr><td class="checkbox"><input class="check-one check" type="checkbox" /></td><td class="goods"><img src="/untitled01_war_exploded/images/1-3.jpg" alt="" /><span>Sony/索尼 DSC-WX300</span></td><td class="price">1428.50</td><td class="count"><span class="reduce"></span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">1428.50</td><td class="operation"><span class="delete">刪除</span></td></tr><tr><td class="checkbox"><input class="check-one check" type="checkbox" /></td><td class="goods"><img src="/untitled01_war_exploded/images/1-4.jpg" alt="" /><span>Fujifilm/富士 instax mini 25</span></td><td class="price">640.60</td><td class="count"><span class="reduce"></span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">640.60</td><td class="operation"><span class="delete">刪除</span></td></tr></tbody> </table><div class="foot" id="foot"><label class="fl select-all"><input type="checkbox" class="check-all check"/> 全選</label><a class="fl delete" id="deleteAll" href="javascript:;">刪除</a> <%-- <div class="fr closing" onclick=""><a class="fr closing" id="#" href="/untitled01_war_exploded/JSP/Product.jsp">返回</a></div>--%><div class="fr closing" onclick="window.location.href='Product.jsp';">返回</div><div class="fr closing">結(jié) 算</div><div class="fr total">合計(jì):¥<span id="priceTotal">0.00</span></div><div class="fr selected" id="selected">已選商品<span id="selectedTotal">0</span>件<span class="arrow up">︽</span><span class="arrow down">︾</span></div><div class="selected-view"><div id="selectedViewList" class="clearfix"><!--<div><img src="images/1.jpg"><span>取消選擇</span></div>--></div><span class="arrow">◆<span>◆</span></span></div> </div> </body></html>37
gitee代碼地址
untitled01: JAVAWEB的servlet登錄的源碼
總結(jié)
以上是生活随笔為你收集整理的JAVA WEB 中间件为SERVLET(五)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: SketchUp Pro 2021 fo
- 下一篇: 分形在山地生成中的应用[1]---中点位