一、前端代码:
前端采用标签库,需要导入
<%@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);//跳转到前端页面
三、效果展示: