当前位置:网站首页>Web17 -- use of El and JSTL
Web17 -- use of El and JSTL
2022-04-23 12:33:00 【Luoluo hushengwei】
hello, Hello everyone , I'm here again , What I want to share with you today is EL And JSTL Use :
Today's content is based on the knowledge of last time
Catalog
3. Shopping cart optimization interface (Car.jsp)
1.index.jsp main interface
<%@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> welcome Source planet SuperMarket</h1>
<p> Honourable ${user.uname}</p>
<p><a href="Car.jsp" class="btn btn-primary"></a></p>
<p><a href="doExit.jsp" class="btn btn-warning"> sign out </a></p>
</div>
</div>
<table class="table">
<tr>
<th> Item number </th>
<th> Name of commodity </th>
<th> item pricing </th>
<th> Commodity Description </th>
<th> operation </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>
<%-- Link here need to take id In the past --%>
<a href="doAddCar.jsp?id=${g.id}" class="btn btn-primary"> Add cart </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;// Default first page
if(parameter!=null){
ipage=Integer.parseInt(parameter);
}
// Get goods biz
IGoodsBiz goodsBiz=new GoodsBizImpl();
// Find out the goods , And put it in the request domain
session.setAttribute("goods",goodsBiz.getAll(ipage));
// Calculate the number of pages Bring to index.jsp
int row=goodsBiz.getRowCount();
session.setAttribute("maxPage",(int)Math.ceil(row*1.0/2) );
session.setAttribute("ipage",ipage);
// Hope to carry the data index.jsp in
response.sendRedirect("index.jsp");
%>
3. Shopping cart optimization interface (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> Welcome to Yuanxing shopping cart </h1>
<p> Honourable ${user.uname}</p>
<p><a href="doExit.jsp" class="btn btn-warning"> sign out </a></p>
</div>
</div>
<table class="table">
<tr>
<th> Product id </th>
<th> Name of commodity </th>
<th> Number of goods </th>
<th> Commodity price </th>
<th> operation </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"> Delete </a>
</td>
</tr>
</c:forEach>
</table>
<h1 class="alert alert-info">
The total price of the current shopping cart
<small></small>
<a href="doClear.jsp" class="btn btn-danger"> Click me to settle </a>
</h1>
</body></html>
版权声明
本文为[Luoluo hushengwei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231226294856.html
边栏推荐
- BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
- XinChaCha Trust SSL Organization Validated
- Web17——EL与JSTL的使用
- QT redraw events and cuts
- How does sqlserver insert or update the number of weeks of the day instead of text
- 解决disagrees about version of symbol device_create
- I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
- 关于使用Go语言创建WebSocket服务浅谈
- 0基础可以考CPDA数据分析师证书吗
- Symmetric encryption, certificate encryption
猜你喜欢
Qt双缓冲绘图
解决disagrees about version of symbol device_create
QT draw text
编程辅助工具推荐:图片工具snipaste
Running error: unable to find or load the main class com xxx. Application
AI 视频云 VS 窄带高清,谁是视频时代的宠儿
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
航芯技术分享 | ACM32 MCU安全特性概述
QT draw image
随机推荐
Stm32cubeprogrammer basic instructions
【vulnhub靶场】-dc2
S2-062 remote command execution vulnerability recurrence (cve-2021-31805)
Qt一个进程运行另一个进程
Fastjson 2 来了,性能继续提升,还能再战十年
异步时钟亚稳态 的解决方案——多bit信号
On lambda powertools typescript
Lesson 26 static member functions of classes
QT redraw events and cuts
After a circle, I sorted out this set of interview questions..
同态加密技术学习
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
uni-app 原生APP-本地打包集成极光推送(JG-JPUSH)详细教程
Zigbee之CC2530最小系统及寄存器配置(1)
A graphic designer's fantasy world | ones characters
box-sizing
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
Solution of asynchronous clock metastability -- multi bit signal
What is a gateway
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]