当前位置:网站首页>Web17——EL与JSTL的使用
Web17——EL与JSTL的使用
2022-04-23 12:26:00 【洛洛虎虎生威】
hello,大家好,我又来啦,今天要和大家分享的是EL与JSTL的使用:
今天的内容是基于上次的知识哦
目录
1.index.jsp 主界面
<%@page import="com.zking.pojo.Goods"%>
<%@page import="com.zking.biz.impl.GoodsBizImpl"%>
<%@page import="com.zking.biz.IGoodsBiz"%>
<%@page import="com.zking.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>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<style>
td:nth-child(3)::before{
content: "$";
}
</style>
</head>
<body>
<c:if test="${user==null}">
<c:redirect url="login.jsp"></c:redirect>
</c:if>
<c:if test="${empty goods}"><c:redirect url="doIndex.jsp"></c:redirect></c:if>
<div class="jumbotron">
<div class="container">
<h1>欢迎光临 源星球SuperMarket</h1>
<p>尊贵的${user.uname}</p>
<p><a href="Car.jsp" class="btn btn-primary"></a></p>
<p><a href="doExit.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="${goods}" var="g">
<tr>
<td>${g.id}</td>
<td>${g.name}</td>
<td>${g.price}</td>
<td>${g.info}</td>
<td>
<div class="btn-group btn-group-xs">
<button class="btn btn-primary"><span class="glyphicon glyphicon-tags"></span></button>
<%--链接这里需要带id过去 --%>
<a href="doAddCar.jsp?id=${g.id}" class="btn btn-primary">添加购物车</a>
</div>
</td>
</tr>
</c:forEach>
</table>
<div style="text-align:center">
<ul class="pagination" style="">
<li>
<a href="doIndex.jsp?ipage=${Math.max(i-1,1)}">
<span aria-hidden="true">«</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=${i+1==maxPage?maxPage:i+1}" aria-label="Next"><span aria-hidden="true">»</span></a></li>
</ul>
</div>
</body></html>
2.doIndex.jsp
<%@page import="com.zking.pojo.Goods"%>
<%@page import="java.util.List"%>
<%@page import="com.zking.biz.impl.GoodsBizImpl"%>
<%@page import="com.zking.biz.IGoodsBiz"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String parameter=request.getParameter("ipage");
int ipage=1;//默认第一页
if(parameter!=null){
ipage=Integer.parseInt(parameter);
}
//得到商品biz
IGoodsBiz goodsBiz=new GoodsBizImpl();
//将商品查询出来,并且放到请求域当中
session.setAttribute("goods",goodsBiz.getAll(ipage));
//算出页数 带到index。jsp
int row=goodsBiz.getRowCount();
session.setAttribute("maxPage",(int)Math.ceil(row*1.0/2) );
session.setAttribute("ipage",ipage);
//希望把数据携带index.jsp中
response.sendRedirect("index.jsp");
%>
3.购物车优化界面(Car.jsp)
<%@page import="com.zking.pojo.User"%>
<%@page import="com.zking.vo.CarItem"%>
<%@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>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="${pageContext.request.contextPath}/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>
<%
Object obj=session.getAttribute("user");
if(obj==null){
response.sendRedirect("login.jsp");
return;
}
%>
<body>
<div class="jumbotron">
<div class="container">
<h1>欢迎光临源星球购物车</h1>
<p>尊贵的${user.uname}</p>
<p><a href="doExit.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.id}</td>
<td style="line-height: 30.5px;">${c.goods.name}</td>
<td>
<div class="input-group" style="width: 120px;margin: auto;">
<span class="input-group-btn">
<a href="doUpdCar.jsp?id=${c.goods.id}&type=0" class="btn btn-default" type="button">-</a>
</span>
<input type="number" onblur="location.href='doUpdCar.jsp?id=${c.goods.id}&count='+this.value" value="${c.count}" class="form-control">
<span class="input-group-btn">
<a href="doUpdCar.jsp?id=${c.goods.id}&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?id=${c.goods.id}" 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>
版权声明
本文为[洛洛虎虎生威]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_65975275/article/details/124353549
边栏推荐
- Idea database navigator plug-in
- 天梯赛赛前练习
- 第二十五课 类的静态成员变量
- C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
- QT interprocess communication
- 外包干了五年,废了...
- Intelligent multi line elastic cloud adds independent IP address. How to realize multi line function?
- 欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
- 没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
- QT draw image
猜你喜欢
[unity note] basic lighting in l4unity
SQL exercise (I)
The database navigator uses the default MySQL connection prompt: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä’ is unrecognized or repres
A graphic designer's fantasy world | ones characters
Force buckle - 70 climb stairs
智能多线弹性云增加独立的IP地址,如何实现多线功能?
【unity笔记】L4Unity中的基础光照
力扣刷题之完全二叉树的节点个数
CGC: contractual graph clustering for community detection and tracking
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
随机推荐
第二十五课 类的静态成员变量
How to switch PHP version in Windows 2008 system
如果你是一个Golang面试官,你会问哪些问题?
How to expand the capacity of the server in the 100 million level traffic architecture? Well written!
传统企业如何应对数字化转型?这些书给你答案
Nativeformysql connects to MySQL 8 prompt: 1251 - client does not support authentication protocol
SQL exercise (I)
Markdown grammar learning
Relu function of activation function
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
RT-thread中关键词解释及部分API
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
解锁OpenHarmony技术日!年度盛会,即将揭幕!
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
Outsourcing for five years, abandoned
Qt绘制文字
甲辰篇 創世紀《「內元宇宙」聯載》
编程辅助工具推荐:图片工具snipaste
SSL证书退款说明
A detailed explanation of head pose estimation [collection of good articles]