主页面index
在这里可以游览商品信息与加入购物车
这是代码
<%@page import="entity.Goods"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.GoodsDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>
<script type="text/javascript">
function gm(bid) {
location.href="dogwc.jsp?bid="+bid;
}
</script>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
</head>
<body>
<table class="table">
<tr>
<td>商品编号</td>
<td>商品名称</td>
<td>商品单价</td>
<td>商品介绍</td>
<td>商品图片</td>
<td>操作</td>
</tr>
<%
GoodsDao gd = new GoodsDao();
ArrayList<Goods> glist=gd.getAll();
for(Goods g:glist){
%>
<tr>
<td><%=g.getBid() %></td>
<td><%=g.getBname() %></td>
<td><%=g.getBprice() %></td>
<td><%=g.getBinfo() %></td>
<td>
<img alt="" src="<%=g.getBface() %>">
</td>
<td>
<button onclick="gm(<%=g.getBid()%>)" class="btn btn-success">加入购物车</button>
</td>
</tr>
<%} %>
</table>
</body>
</html>
购物车
这里可以增加商品数量,计算商品总价,与删除商品
代码
<%@page import="entity.Orderltem"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<script type="text/javascript">
function $(id) {
return document.getElementById(id);
function xg(obj,bid) {
var gunmber = obj.value;
location.href="dogwc.jsp?bid="+bid+"&gn="+gnumber;
}
function jj(obj,a,bid) {
if(a=='-'){
var gnumber=parseInt($("text").value)-1;
location.href="dogwc.jsp?bid="+bid+"&gn="+gnumber;
}else if(a=='+'){
var gnumber=parseInt($("text").value)+1;
location.href="dogwc.jsp?bid="+bid+"&gn="+gnumber;
}
}
}
</script>
</head>
<body>
<h1 align="center">
<a href="index.jsp">
<span class="glyphicon glyphicon-home"></span>
</a>
</h1>
<table class="table table-hover">
<tr>
<td>商品图片</td>
<td>商品名称</td>
<td>商品单价</td>
<td>商品介绍</td>
<td>商品数量</td>
<td>订单总价</td>
<td>操作一下</td>
</tr>
<%
ArrayList<Orderltem> olist = (ArrayList<Orderltem>)session.getAttribute("olist");
for(Orderltem oi:olist){
%>
<tr>
<td>
<img alt="" src="<%=oi.getG().getBface() %>">
</td>
<td><%=oi.getG().getBname()%></td>
<td><%=oi.getG().getBprice() %></td>
<td><%=oi.getG().getBinfo() %></td>
<td>
<button class="btn" onclick="jj(this,'-',<%=oi.getG().getBid()%>">-</button>
<input onblur="xg(this,<%=oi.getG().getBid()%>)" style="width: 60px;text-align: center;" type="text" value="<%=oi.getGnumber() %>">
<button class="btn" onclick="jj(this,'+',<%=oi.getG().getBid()%>">+</button>
</td>
<td><%=oi.getSumPrice() %></td>
<td>
<button onclick="sc(<%=oi.getG().getBid()%>)" class="btn btn-danger">删除</button>
</td>
</tr>
<%} %>
</table>
<button class="btn" >总价</button>
</body>
</html>
删除页面
这里是删除方法的代码
<%@page import="java.util.ArrayList"%>
<%@page import="entity.Orderltem"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String id= request.getParameter("bid");
int bid=Integer.valueOf(id);
ArrayList<Orderltem> olist= (ArrayList<Orderltem>)session.getAttribute("olist");
for(int i=0;i<olist.size();i++){
if(olist.get(i).getG().getBid()==bid){
olist.remove(i);
response.sendRedirect("gwc.jsp");
}
session.setAttribute("olist", olist);
}
%>