jspEL与JSTL的使用
购物车(优化)
<%@page import="java.util.List"%>
<%@page import="com.test.vo.CarItem"%>
<%@page import="com.test.pojo.User"%>
<%@ 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>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<style>
td:nth-child(4)::before,
small {
content: "$";
}
* {
outline: none !important;
}
td,
th {
text-align: center;
}
input {
text-align: center;
}
</style>
</head>
<c:if test="${user == null}">
<jsp:forward page="login.jsp"/>
</c:if>
<body>
<div class="jumbotron">
<div class="container">
<h1>欢迎光临星星购物车</h1>
<p>尊贵的${user.userAccount}</p>
<p>
<a href="doExit.jsp" class="btn btn-warning">退出登录</a>
<a href="doIndex.jsp" class="btn btn-warning">返回</a>
</p>
</div>
</div>
<table class="table">
<tr>
<th>商品序号</th>
<th>商品名称</th>
<th>商品个数</th>
<th>商品总价</th>
<th>操作</th>
</tr>
<c:forEach items="${car}" var="c">
<tr>
<td style="line-height: 30.5px;">${c.goods.goodsId}</td>
<td style="line-height: 30.5px;">${c.goods.goodsName}</td>
<td>
<div class="input-group" style="width: 120px;margin: auto;">
<span class="input-group-btn">
<a href="doUpdCar.jsp?goodsId=${c.goods.goodsId}&type=0" class="btn btn-default" type="button">-</a>
</span>
<input οnblur="location.href='doUpdCar.jsp?goodsId=${c.goods.goodsId}&count='+this.value" value="${c.count}" type="text" class="form-control">
<span class="input-group-btn">
<a href="doUpdCar.jsp?goodsId=${c.goods.goodsId}&type=1" class="btn btn-default" type="button">+</a>
</span>
</div>
</td>
<td style="line-height: 30.5px;">${c.sum}</td>
<td style="line-height: 30.5px;">
<a href="doDelCar.jsp?goodsId=${c.goods.goodsId}" class="btn btn-primary">删除</a>
</td>
</tr>
</c:forEach>
</table>
<h1 class="alert alert-info">
当前购物车总价
<small></small>
<a href="doClear.jsp" class="btn btn-danger">点我结算</a>
</h1>
</body>
</html>
主页界面新增(分页)
<%@page import="com.test.pojo.Goods"%>
<%@page import="com.test.biz.impl.GoodsBizImpl"%>
<%@page import="com.test.biz.IGoodsBiz"%>
<%@page import="com.test.pojo.User"%>
<%@ 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>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>SuperMarket</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<style>
td:nth-child(3)::before{
content: "$";
}
</style>
</head>
<c:if test="${user == null}">
<jsp:forward page="login.jsp"/>
</c:if>
<c:if test="${empty goods}">
<jsp:forward page="login.jsp"/>
</c:if>
<body>
<div class="jumbotron">
<div class="container">
<h1>欢迎光临胡阿玛SuperMarket</h1>
<p>尊贵的${user.userAccount}</p>
<p>
<a href="car.jsp" class="btn btn-primary">🛒</a>
</p>
</div>
</div>
<table class="table">
<tr>
<th>商品序号</th>
<th>商品名称</th>
<th>商品单价</th>
<th>商品描述</th>
<th>操作</th>
</tr>
<c:forEach items="${goods}" var="g">
<tr>
<td>${g.goodsId}</td>
<td>${g.goodsName}</td>
<td>${g.goodsPrice}</td>
<td>${g.goodsInfo}</td>
<td>
<div class="btn-group btn-group-xs">
<a href="doAddCar.jsp?goodsId=${g.goodsId}" class="btn btn-primary">添加购物车</a>
</div>
</td>
</tr>
</c:forEach>
</table>
<div style="text-align: center">
<ul class="pagination">
<li>
<a href="doIndex.jsp?ipage=${Math.max(ipage-1,1)}">
<span>«</span>
</a>
</li>
<c:forEach begin="1" end="${maxPage}" var="i">
<li class="${ipage==i?"active":"" }">
<a href="doIndex.jsp?ipage=${i}">${i}</a></li>
</c:forEach>
<li>
<a href="doIndex.jsp?ipage=${ipage+1>maxPage?maxPage:ipage+1}">
<span>»</span>
</a>
</li>
</ul>
</div>
</body>
</html>