简单的jsp分页判断

<c:choose>
<c:when test="${maxPage == 0}">
<div align="center"><h3><font color="red">没有数据!!!!!</font></h3></div>
</c:when>
<c:otherwise>
<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>】页   <font color="red">${page}</font>/<font color="red">${maxPage}</font>  
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=1&username=<%=user.getRealName() %>">首页</a>
 
<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>
 
<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>
 
<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>
 
<a href="<%=basePath %>ApplyServlet?b=findAllFund&digit=3&param=30&page=${maxPage}&username=<%=user.getRealName() %>">尾页</a>
   
<input type="text" id="pageId" value="${page }" style="width: 30px" /> 
<input type="button" value="跳转" οnclick="mySkip()" />
<input type="hidden" value="${maxPage }" id="maxId" />
</td>

</tr>
</table>
</c:otherwise>
</c:choose>

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现 JSP 分页功能需要以下步骤: 1. 使用 SQL 语句查询出所有符合条件的数据总条数,并存储在一个变量中。 2. 通过计算,确定分页的页数。可以通过数据总条数和每页显示的记录数来计算出总页数。 3. 接收当前页码的参数,并将其与每页显示的记录数相乘,从而计算出起始记录的位置。 4. 使用 SQL 语句查询出当前页需要显示的记录。可以使用 LIMIT 子句来限制查询结果的数量和位置。 5. 将查询结果通过 JSP 页面进行展示。 下面是一个简单JSP 分页实现示例: ```java <% int currentPage = Integer.parseInt(request.getParameter("currentPage")); int pageSize = 10; int totalCount = ... ; // 查询数据总条数 int totalPage = (totalCount + pageSize - 1) / pageSize; // 计算总页数 int startIndex = (currentPage - 1) * pageSize; // 计算起始记录位置 List<Data> dataList = ... ; // 查询当前页需要显示的记录 %> <table> <% for (Data data : dataList) { %> <tr> <td><%= data.getId() %></td> <td><%= data.getName() %></td> <td><%= data.getValue() %></td> </tr> <% } %> </table> <div> <% if (currentPage > 1) { %> <a href="?currentPage=<%= currentPage - 1 %>">上一页</a> <% } %> <% if (currentPage < totalPage) { %> <a href="?currentPage=<%= currentPage + 1 %>">下一页</a> <% } %> </div> ``` 在上面的示例中,currentPage 表示当前页码,pageSize 表示每页显示的记录数,totalCount 表示数据总条数,startIndex 表示起始记录位置,dataList 表示当前页需要显示的记录。通过计算,可以得到 totalPage 表示总页数。在 JSP 页面中,使用 for 循环遍历 dataList,将查询结果进行展示。同时,通过判断 currentPage 和 totalPage,可以实现上一页和下一页的链接。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值