<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 解析请求参数，并植入FORM中
<script type="text/javascript">
		//解析已经绑定参数
		var url = "${url}";
		var array = url.split("?");
		for (var len = 0; len < array.length; len++) {
			//第二次切割
			var arr = array[len].split("=");
			alert(arr[0] + "="+arr[1]);
		}
</script> --%>
<script type="text/javascript">
	function _go() {
		var pageNO = $("#pageCode").val();//获取文本框中的当前页码
		if(!/^[1-9]\d*$/.test(pageNO)) {//对当前页码进行整数校验
			alert('请输入正确的页码！');
			return;
		}
		var page = "${pageSize}";
		page = parseInt(page);
		if(pageNO > page) {//判断当前页码是否大于最大页
			alert('请输入正确的页码！');
			return;
		}
		var pageno = "${pageNO}";
		pageno = parseInt(pageno);
		if(pageNO == pageno) {
			alert("您处于" + pageNO + "页!");
			return;
		}
		location = "${pageContext.request.contextPath}${url}" + pageNO;
	}
</script>


<div class="divBody">
	<div id="testDIV"></div>
	<form action="" id="myForm" method="post"></form>
  		<div class="btn-group">
		    <%--上一页 --%>
		    <span class="btn btn-lowblue radius">
			    <c:choose>
			      <c:when test="${pageNO eq 1 }">
			        <a class="active">上一页</a>
			      </c:when>
			      <c:otherwise>
			        <a href="${pageContext.request.contextPath }${url}${pageNO-1}" class="aBtn bold">上一页</a>
			      </c:otherwise>
			    </c:choose>
    		</span>
		    <%-- 计算begin和end --%>
		    <c:choose>
		      <%-- 如果总页数<=6，那么显示所有页码，即begin=1 end=${pageSize} --%>
		      <c:when test="${pageSize <= 6 }">
		        <c:set var="begin" value="1"/>
		        <c:set var="end" value="${pageSize }"/>
		      </c:when>
		      <c:otherwise>
		        <%-- 设置begin=当前页码-2，end=当前页码+3 --%>
		        <c:set var="begin" value="${pageNO-2 }"/>
		        <c:set var="end" value="${pageNO+3 }"/>
		        <c:choose>
		          <%-- 如果begin<1，那么让begin=1 end=6 --%>
		          <c:when test="${begin<1}">
		            <c:set var="begin" value="1"/>
		            <c:set var="end" value="6"/>
		          </c:when>
		          <%-- 如果end>最大页，那么begin=最大页-5 end=最大页 --%>
		          <c:when test="${end>pageSize}">
		            <c:set var="begin" value="${pageSize-5 }"/>
		            <c:set var="end" value="${pageSize}"/>
		          </c:when>
		        </c:choose>
		      </c:otherwise>
		    </c:choose>
    
		    <%-- 显示页码列表 --%>
		    <c:forEach var="page" begin="${begin }" end="${end }">
		      <c:choose>
		        <c:when test="${page eq pageNO }">
		          <span class="btn btn-lowblue radius"><a  class="active">${page }</a></span>
		        </c:when>
		        <c:otherwise>
		          <span class="btn btn-lowblue radius"><a href="${pageContext.request.contextPath }${url}${page}" class="aBtn">${page }</a></span>
		        </c:otherwise>
		      </c:choose>
		    </c:forEach>
		    
    
		    <%-- 显示点点点 --%>
		    <c:if test="${end < pageSize }">
		      <a  class="active">...</a> 
		    </c:if>
    
		     <%--下一页 --%>
		     <span class="btn btn-lowblue radius">
			     <c:choose>
			      <c:when test="${pageNO eq pageSize || pageSize == 0}">
			        <a class="active">下一页</a>
			      </c:when>
			      <c:otherwise>
			        <a href="${pageContext.request.contextPath }${url}${pageNO+1}" class="aBtn bold">下一页</a>
			      </c:otherwise>
			    </c:choose>
			 </span>
			 <span class="btn" style="cursor: default;">
    			您当前位于:${pageNO}页
    		</span>
    
    <%-- 共N页 到M页 --%>
    <span class="btn" style="cursor: default;">共<a class="active">${pageSize }</a>页</span>
    <span class="btn" style="cursor: default;">到<a class="active" style="max-height: 36px;min-height: 34px"><input type="text" id="pageCode" value="${pageNO }" class="input-text radius" style="width: 36px;height:22px" maxlength="3"/></a>页</span>
    <span class="btn btn-lowblue radius"><a href="javascript:_go();" class="active">确定</a></span>
    <a href="#" style="overflow:hidden" class="active"></a>
  </div>
</div>