jsp分頁處理

來源:互聯網
上載者:User

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@page import="cn.com.gnnt.test.Pager"%><%int pageSize = 10;int pieceSize = 5;String pageName = "pager.jsp";//當前頁碼String s = request.getParameter("currentPage");int currentPage = 0;if(s!=null){currentPage = Integer.parseInt(s);}//類比資料List<String> list = (List<String>)session.getAttribute("list");if(list == null || list.size() == 0){list = new ArrayList<String>();Random r = new Random();for(int i=0;i<100;i++){list.add("Hello, I'm " + ((char)('A' + r.nextInt(26))) + ". " + i);}session.setAttribute("list", list);}//類比資料Pager pager = new Pager(list.size(), pageSize, pieceSize);pager.setCurrentPage(currentPage);%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <title>My JSP 'Pager.jsp' starting page</title><style type="text/css"><!--  a {text-decoration: none;}.thinBorder{border-collapse:collapse;}  .thinBorder th{background:#ffffff;border:solid 1px #000000;}  .thinBorder td{background:#ffffff;border:solid 1px #000000;}  -->   </style><script type="text/javascript">function jump(currentPage){var cp = document.getElementById(currentPage).value;cp = parseInt(cp) - 1;window.location='<%=pageName%>?currentPage='+ cp;}</script></head><body><!-- 分頁展示資料 --><div id="pagerData"><table width="100%" class="thinBorder"><tr><th width="50px">編號</th><th>內容</th></tr><%for(int i=pager.getCurrentStart();i<pager.getCurrentEnd();i++){%><tr><td><%=i + 1%></td><td><%=list.get(i)%></td></tr><%}%></table><table><tr><td><div><%if(pager.isFirstPage()){%>首頁 | 上一頁 | <%}else{%><a href="<%=pageName%>?currentPage=0">首頁</a> | <a href="<%=pageName%>?currentPage=<%=pager.getCurrentPage() - 1%>">上一頁</a> <%if(!pager.isFirstPiece()){int cp = pager.getCurrentPage() - pager.getPieceSize();%> <a href="<%=pageName%>?currentPage=<%=cp%>">···</a> <%}}for(int i=pager.getPageStart();i<pager.getPageEnd();i++){if(i==pager.getCurrentPage()){out.print(i + 1 + " ");}else{%> <a href="<%=pageName%>?currentPage=<%=i%>"><%=i + 1%></a> <%}}%><%if(pager.isLastPage()){%>下一頁 | 末頁 | <%}else{if(!pager.isLastPiece()){int cp = pager.getCurrentPage() + pager.getPieceSize();if(cp >= pager.getPageCount()){cp = pager.getPageCount() - 1;}%> <a href="<%=pageName%>?currentPage=<%=cp%>">···</a> <%}%><a href="<%=pageName%>?currentPage=<%=pager.getCurrentPage() + 1%>">下一頁</a> | <a href="<%=pageName%>?currentPage=<%=pager.getPageCount()%>">末頁</a><%}%></div></td><td><div><input type="text" id="currentPageNo" name="currentPageNo" size="2" title="輸入頁碼,按斷行符號快速跳轉" value="<%=currentPage + 1%>"  onkeydown="if(event.keyCode==13) {jump('currentPageNo')}" /><input type="button" value="跳轉" onclick="jump('currentPageNo')"/></div></td><td><div>第<%=pager.getCurrentPage() + 1%>頁 / 共<%=pager.getPageCount()%>頁 總記錄數:<%=pager.getTotalCount()%>條,<%if(pager.getTotalCount()==0){out.print("無顯示");}else{%>顯示第<%=pager.getCurrentStart() + 1%>條到第<%=pager.getCurrentEnd()%>條記錄<%}%></div></td></tr></table></div><!-- 分頁展示資料 --></body></html>

其他分頁方式:

用jsp進行資料分頁顯示的一個實現(http://www.ibm.com/developerworks/cn/java/l-jspdisp/index.html)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.