码迷,mamicode.com
首页 > Web开发 > 详细

jsp实现简单的分页

时间:2014-11-24 20:29:33      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   java   for   

效果如下:
bubuko.com,布布扣
<%-- Document : page Created on : 2014-11-18, 8:55:02 Author : HJZ --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <script language= "javascript"> function dumpTo(tot) { //函数参数定义时不加var,否则出错 var pageMsg = document.getElementById("pageTo").value; var patrn=/^\d+$/; if (patrn.test(pageMsg)) { if(parseInt(pageMsg)<1 || parseInt(pageMsg)>parseInt(tot)) return; window.location.href="page.jsp?page=" + pageMsg; } } </script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>分页显示</title> </head> <body> <% int pageCur = 0; int pageTot = 20; int pageBegin = 0; String curPage = request.getParameter("page"); if(curPage == null) pageCur = 1; else pageCur = Integer.valueOf(curPage); pageBegin = pageCur-5; if(pageBegin < 1) pageBegin = 1; %> <talbe border="10"> <tr> <%if(pageCur!=1){%> <td> <input type="submit" name="skip" value="上一页" onclick="javascript:location.href=‘page.jsp?page=<%=pageCur-1%>‘"> </td> <%}%> <% for(int i=pageBegin, j=1; j<=10 && i<=pageTot; ++i, ++j) {%> <%if(i == pageCur){%> <td> <%=i%> </td> <%} else {%> <td> <input type="submit" name="skip" value="<%=i%>" onclick="javascript:location.href=‘page.jsp?page=<%=i%>‘"> </td> <%}%> <% } %> <%if(pageCur!=pageTot){%> <td> <input type="submit" name="skip" value="下一页" onclick="javascript:location.href=‘page.jsp?page=<%=pageCur+1%>‘"> </td> <%}%> <td><%=pageTot%></td> <td width="105px"> 向第<input type="text" id="pageTo"></td> <td> <input type="button" name="skip" value="跳转" onclick="dumpTo(<%=pageTot%>)"> <!--传递总页数--> </td> </tr> </table> </body> </html>

 

jsp实现简单的分页

标签:style   blog   http   io   ar   color   sp   java   for   

原文地址:http://www.cnblogs.com/hujunzheng/p/4119332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!