首页 > 代码库 > jsp实现简单的分页
jsp实现简单的分页
效果如下:
<%-- 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=http://www.mamicode.com/‘page.jsp?page=‘"> </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=http://www.mamicode.com/‘page.jsp?page=‘"> </td> <%}%> <% } %> <%if(pageCur!=pageTot){%> <td> <input type="submit" name="skip" value="下一页" onclick="javascript:location.href=http://www.mamicode.com/‘page.jsp?page=‘"> </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实现简单的分页
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。