编写步骤:
- 数据库的设计(每个表都要序列)
- 编写包
- 开发的界面
- 购物车的具体实现代码
绑定主界面数据
加入到我的购物车,对商品数量的更改以及商品总价的计算
实现删除我的购物车商品的方法
修改商品数量
结账
订单
订单项
5.方法
1.数据库的设计
--用户表
create table sp_user(
uuid int primary key not null,
uname varchar2(25) not null,
upwd varchar2(25)not null,
address varchar2(50),
tel varchar2(50)
)
--商品表
create table sp_goods(
gid int primary key not null,
gname varchar2(25)not null,
gprice number
)
--订单表
create table sp_order(
ooid int primary key not null,
address varchar2(50),
orderPrice float,
uuid int
)
--订单明细表/订单项
create table sp_orderitem(
otid int primary key not null,
ooid int,
gid int,
scount int,
orderItemPrice float
)
--购物车表
create table sp_cart(
cid int primary key not null,
gname varchar2(25),
gprice float,
gcount int,
cprice float,
uuid int
)
--序列
create sequence 序列名;
--触发器
create or replace trigger 触发器名
before insert
on 表名
for each row
begin
:new. 要设置为标识列的字段:= 序列名.nextval;
end;
2.编写包
3.开发的界面
- 用户登录界面(index.jsp)
- 主页面(shopping.jsp)
- 购物车界面(myCart.jsp)
- 订单界面(myOrder.jsp)
- 订单详情界面(myOrderItem.jsp)
用户登录界面(index.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>带下雪背景的登录注册页面 </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Custom Theme files -->
<link rel="stylesheet" type="text/css" href="https://www.jq22.com/jquery/font-awesome.4.6.0.css">
<link href="${pageContext.request.contextPath }/static/css/snow.css" rel="stylesheet" type="text/css" media="all" />
<link href="${pageContext.request.contextPath }/static/css/style.css" rel="stylesheet" type="text/css" media="all" />
<!-- //Custom Theme files -->
</head>
<body>
<div class="snow-container">
<div class="snow foreground"></div>
<div class="snow foreground layered"></div>
<div class="snow middleground"></div>
<div class="snow middleground layered"></div>
<div class="snow background"></div>
<div class="snow background layered"></div>
</div>
<div class="top-buttons-agileinfo">
<!-- <a href="index.html" class="active">登录</a> --><a href="${pageContext.request.contextPath }/home/signup.jsp">注册</a>
</div>
<h1>带下雪背景的登录注册页面</h1>
<div class="main-agileits">
<!--form-stars-here-->
<div class="form-w3-agile">
<h2 class="sub-agileits-w3layouts">登录系统</h2>
<form action="${pageContext.request.contextPath }/indexServlet.do" method="post">
<input type="text" name="uname" placeholder="请输入账号" required="" />
<input type="password" name="upwd" placeholder="请输入密码" required="" />
<!-- <a href="#" class="forgot-w3layouts">忘记密码 ?</a> -->
<div class="submit-w3l">
<input type="submit" value="登录">
</div>
<p class="p-bottom-w3ls"><a href="${pageContext.request.contextPath }/home/signup.jsp">这里注册</a>如果你还没有一个账号.</p>
</form>
</div>
</div>
<!--//form-ends-here-->
<!-- copyright -->
<div class="copyright w3-agile">
<p> © 2019 带下雪背景的登录注册页面 . All rights reserved | Design by <a href="#">Reserved</a></p>
</div>
<!-- //copyright -->
<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
</body>
</html>
主页面(shopping.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<h1>
<a href="${pageContext.request.contextPath}/loadCartDataServlet.do">我的购物车</a>
<a href="${pageContext.request.contextPath}/myOrderServlet.do">我的订单</a>
</h1>
</center>
<c:if test="${empty listGoods}">
<jsp:forward page="/myLoadDataServlet.do"></jsp:forward>
</c:if>
<table border="4px" style="text-align: center;" height="600px" width="1000px" align="center" >
<tr>
<td>商品序号</td>
<td>商品名称</td>
<td>商品单价</td>
<td>操作</td>
</tr>
<c:forEach items="${listGoods }" var="g">
<tr style="font-size:20px;">
<td >${g.gId }</td>
<td>${g.gName }</td>
<td>${g.gPrice }</td>
<td >
<!-- 加入购物车 -->
<a href="${pageContext.request.contextPath }/addCartServlet.do?gid=${g.gId}">
<img src="${pageContext.request.contextPath}/static/images/1.ico" width="60px"/>
</a>
<!-- 立即购买:直接跳转到结账页面,不经过购物车 -->
<a href="#">
<img src="${pageContext.request.contextPath}/static/images/8.ico" width="50px"/>
</a>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
购物车界面(myCart.jsp)
<%@page import="com.zking.entity.OrderItem"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的购物车</title>
<script type="text/javascript">
// 修改购物车里面商品数量和价格小计
function update(cid,gname){// 参数 cid:文本框的id(购物车的序号);gname:商品名字
// 获取到用户修改后的