分页程序的实现

一、前端代码:
前端采用标签库,需要导入

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="pagging">
    <div class="left">总记录数:${pagination.countSize} -
        总页数:${pagination.countPage}</div>

    <div class="right">
    <c:if test="${pagination.currPage > 1}">
<a  href="<%= request.getContextPath()%>/Order/DisplayOrders?orderStatus=${orderStatus }&page=1">首页</a>
<a  href="<%= request.getContextPath()%>/Order/DisplayOrders?orderStatus=${orderStatus }&page=${pagination.currPage - 1}">上一页</a>
   </c:if>
    <c:forEach var="i" begin="${pagination.currPage - 3<=0?1:pagination.currPage - 3}"	end="${pagination.currPage - 1}">
    <a  href="<%= request.getContextPath()%>/Order/DisplayOrders?orderStatus=${orderStatus }&page=${i}">${i}</a>
    </c:forEach>
    <a class="select">${pagination.currPage}</a>
    <c:forEach var="i" begin="${pagination.currPage + 1}"
    end="${pagination.countPage - pagination.currPage>3?pagination.currPage + 3:pagination.countPage}">
    <a href="<%= request.getContextPath()%>/Order/DisplayOrders?orderStatus=${orderStatus }&page=${i}">${i}</a>
    </c:forEach>
    <c:if test="${pagination.currPage < pagination.countPage}">
    <a  href="<%= request.getContextPath()%>/Order/DisplayOrders?orderStatus=${orderStatus }&page=${pagination.currPage + 1}">下一页</a>
    <a href="<%= request.getContextPath()%>/Order/DisplayOrders?orderStatus=${orderStatus }&page=${pagination.countPage}">尾页</a>
    </c:if>
    </div>
</div>

二、后台实现:

“`
Pagination pagination = new Pagination();
int page = 1;
String p= request.getParameter(“page”);
if (p != null) {
page = Integer.parseInt(p);
}
pagination.setCurrPage(page);
orders = DaoFactory.getOrderDao().getAllOrder(pagination);
request.setAttribute(“pagination”, pagination);
request.setAttribute(“orders”, orders);
request.getRequestDispatcher(“orderedOrder.jsp”).forward(request, response);//跳转到前端页面

三、效果展示:

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值