您现在的位置是:首页 > 电脑技术查询 > web开发

简略的jsp分页判断

编辑:chaxungu时间:2022-10-10 23:24:01分类:web开发

简单的jsp分页判断
<table width="100%" bgcolor="whitesmoke" border="0" align="center" cellpadding="2" cellspacing="2" class="list_bt">
<tr>

<td align="center">
总共【<font color="red">${maxPage}</font>】页 &nbsp;&nbsp;<font color="red">${page}</font>/<font color="red">${maxPage}</font>&nbsp;&nbsp;
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=1&username=<%=user.getRealName() %>">首页</a>
&nbsp;
<c:choose>
<c:when test="${page == 1}">上一页</c:when>
<c:otherwise>
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${page-1}&username=<%=user.getRealName() %>">上一页</a>
</c:otherwise>
</c:choose>
&nbsp;
<c:choose>
<c:when test="${page == 1 || page == 2 || page == 3 || page == 4}">
<c:if test="${maxPage <= 4}">
<c:forEach begin="1" end="${maxPage}" var="i">
<c:if test="${page == i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="red">${i}</font></a>
</c:if>
<c:if test="${page != i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="blue">${i}</font></a>
</c:if>
</c:forEach>
</c:if>
<c:if test="${maxPage > 4}">
<c:forEach begin="1" end="5" var="i">
<c:if test="${page == i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="red">${i}</font></a>
</c:if>
<c:if test="${page != i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="blue">${i}</font></a>
</c:if>
</c:forEach>
</c:if>
</c:when>
<c:when test="${page+2 < maxPage}">
<c:forEach begin="${page-2}" end="${page+2}" var="i">
<c:if test="${page == i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="red">${i}</font></a>
</c:if>
<c:if test="${page != i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="blue">${i}</font></a>
</c:if>
</c:forEach>
</c:when>
<c:otherwise>
<c:forEach begin="${maxPage-4}" end="${maxPage}" var="i">
<c:if test="${page == i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="red">${i}</font></a>
</c:if>
<c:if test="${page != i}">
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${i }&username=<%=user.getRealName() %>"><font color="blue">${i}</font></a>
</c:if>
</c:forEach>
</c:otherwise>
</c:choose>
&nbsp;
<c:choose>
<c:when test="${page == maxPage}">下一页</c:when>
<c:otherwise>
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${page+1}&username=<%=user.getRealName() %>">下一页</a>
</c:otherwise>
</c:choose>
&nbsp;
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${maxPage}&username=<%=user.getRealName() %>">尾页</a>
&nbsp;&nbsp;&nbsp;
<input type="text" id="pageId" value="${page }" style="width: 30px" />&nbsp;
<input type="button" value="跳转" onclick="mySkip()" />
<input type="hidden" value="${maxPage }" id="maxId" />
</td>

</tr>
</table>

function mySkip(){
//var page = document.getElementById("pageId").value ;
var page = parseInt($("#pageId").val()) ;
var maxPage = $("#maxId").val() ;
var re = new RegExp("[0-9]") ;
alert(page) ;
alert(re.test(page)) ;
if(page > 0 && page <= maxPage){
location = "<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&username=<%=user.getRealName() %>&page="+page ;
}else{
alert("无效页数!!!") ;
}
}取整数问题
1.丢弃小数部分,保留整数部分
parseInt(5/2)
2.向上取整,有小数就整数部分加1
Math.ceil(5/2)
3,四舍五入.
Math.round(5/2)
4,向下取整
Math.floor(5/2)