JAVA WEB 中间件为SERVLET(五)

写一个简单的商城

1.登录系统

2.选择商品

        2.1选择的商品会存放在数据库

3.购物车结算

        3.1可以扩展一下,不同的用户登录后查看自己加入到购物车的商品

登录页面上一章已经有了,接下来就是2个JSP页面分别是商品页和购物车页

商品页模板

 购物车模板

商品页缺少一个导航栏,用来实现商品页面和购物车页面的跳转

jsp页面之间的跳转方法

我用的是<a></a>标签,网上有很多方法。这里注意的地方是jsp和jsp通过<a></a>标签跳转样式会失效。处理方法就是用绝对路径

这个就是绝对路径

 

我在这里卡了很久,应为我的项目名称和发布的名称不同

HTML

表格自动添加序号

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动编号</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>编号</td>
        <td>内容</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: JIAHANG
  Date: 2023/1/30
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物页</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"/>&nbsp;全选</label>--%>
<%--    <a class="fl delete" id="deleeAll" href="././JSP/Shopping.jsp">购物车</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">购物车</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>序号</th>
        <th>商品</th>
        <th>单价</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 start
            Using 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">加入购物车</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 start
            Using 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">加入购物车</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 start
            Using 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">加入购物车</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 start
            Using 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">加入购物车</span></td>
    </tr>
    </tbody>
</table>
<%--<a href="././JSP/Shopping.jsp">购物车</a>--%>

</body>

</html>

<%--
  Created by IntelliJ IDEA.
  User: JIAHANG
  Date: 2023/1/30
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物页</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"/>&nbsp;全选</label></th>
        <th>商品</th>
        <th>单价</th>
        <th>数量</th>
        <th>小计</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"/>&nbsp;全选</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">结 算</div>

    <div class="fr total">合计:¥<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登录的源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值