servlet下使用c标签分页

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
<script type="text/javascript">
	function _go() {
		var pc = $("#pageCode").val();//获取文本框中的当前页码
		if(!/^[1-9]\d*$/.test(pc)) {//对当前页码进行整数校验
			alert('请输入正确的页码!');
			return;
		}
		if(pc > ${pb.tp}) {//判断当前页码是否大于最大页
			alert('请输入正确的页码!');
			return;
		}
		location = "${pb.url}&pc=" + pc;
	}
</script>
<div class="divBody">
  <div class="divContent">
    <%--上一页 --%>
<c:choose>
	<c:when test="${pb.pc eq 1 }"><span class="spanBtnDisabled">上一页</span></c:when>
	<c:otherwise><a href="${pb.url }&pc=${pb.pc-1}" class="aBtn bold">上一页</a></c:otherwise>
</c:choose>
        
        

<%--我们需要计算页码列表的开始和结束位置,即两个变量begin和end
计算它们需要通过当前页码!
1. 总页数不足6页--> begin=1, end=最大页
2. 通过公式设置begin和end,begin=当前页-2,end=当前页+3
3. 如果begin<1,那么让begin=1,end=6
4. 如果end>tp, 让begin=tp-5, end=tp
 --%>
 <c:choose>
 	<c:when test="${pb.tp <= 6 }">
 		<c:set var="begin" value="1"/>
 		<c:set var="end" value="${pb.tp }"/>
 	</c:when>
 	<c:otherwise>
 		<c:set var="begin" value="${pb.pc-2 }"/>
 		<c:set var="end" value="${pb.pc + 3}"/>
 		<c:if test="${begin < 1 }">
 		  <c:set var="begin" value="1"/>
 		  <c:set var="end" value="6"/>
 		</c:if>
 		<c:if test="${end > pb.tp }">
 		  <c:set var="begin" value="${pb.tp-5 }"/>
 		  <c:set var="end" value="${pb.tp }"/>
 		</c:if> 		
 	</c:otherwise>
 </c:choose>
 
 <c:forEach begin="${begin }" end="${end }" var="i">
   <c:choose>
   	  <c:when test="${i eq pb.pc }">
   	    <span class="spanBtnSelect">${i }</span>
   	  </c:when>
   	  <c:otherwise>
   	    <a href="${pb.url }&pc=${i}" class="aBtn">${i }</a>
   	  </c:otherwise>
   </c:choose>
 </c:forEach>
    
    <%-- 显示点点点 --%>
    <c:if test="${end < pb.tp }">
      <span class="spanApostrophe">...</span>
    </c:if> 
    
     <%--下一页 --%>
	<c:choose>
		<c:when test="${pb.pc eq pb.tp }"><span class="spanBtnDisabled">下一页</span></c:when>
		<c:otherwise><a href="${pb.url }&pc=${pb.pc+1}" class="aBtn bold">下一页</a></c:otherwise>
	</c:choose>
        
          
    
    <%-- 共N页 到M页 --%>
    <span>共${pb.tp }页</span>
    <span>到</span>
    <input type="text" class="inputPageCode" id="pageCode" value="${pb.pc }"/>
    <span>页</span>
    <a href="javascript:_go();" class="aSubmit">确定</a>
  </div>
</div>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值