posts - 23,comments - 12,trackbacks - 0
最简单的JSP分页实现!
<title>Connect DataSource</title>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<%@ include file="conn.jsp"%>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=guestbook";
Connection con = DriverManager.getConnection(url,"sa","szwen");
 Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
      ResultSet.CONCUR_READ_ONLY); 
             int intPageCount;//总页数
 int intRowCount;//总记录
 int intPageSize;//每页显示记录数
 int intPage;//当前页
 int intNext;//下一页
 int intPrev;//上一页
 int i;
 String strPage;
 strPage = request.getParameter("Page");
 if(strPage == null){intPage = 1;}else{intPage = Integer.parseInt(strPage);}
 String sql = "select * from addressbook_table";
 ResultSet rs = stmt.executeQuery(sql);
 rs.last();
 intRowCount = rs.getRow();
 intPageSize = 5;
 intPageCount = (intRowCount+intPageSize-1)/intPageSize;
 if(intPage>intPageCount){intPage = intPageCount;}
 if(intRowCount<intPageSize){intPage = 1;}
 if(intPage<0){intPage = 1;};
 i=0;
 if(intRowCount>0){
 rs.absolute((intPage-1)*intPageSize+1);
 while(i<intPageSize && !rs.isAfterLast()){
 out.print(rs.getString("phone")+"    ");
 out.print(rs.getString("address")+"    ");
 out.print(rs.getString("name")+"<br>");
 rs.next();
 i++;
 }
 rs.close();
 stmt.close();
 }
 intNext = intPage +1;
 if(intNext> intPageCount){intNext = intPageCount;}
 intPrev = intPage -1;
 if(intPrev< 1){intPrev = 1;}
%>
共 <%=intRowCount%> 记录 共 <%=intPageCount%> 页 每页显示 <%=intPageSize%> 条记录 <a href="show.jsp?Page=<%=intNext%>">intNext</a> <a href="show.jsp?Page=<%=intPrev%>">intPrev</a>
posted on 2005-07-26 08:52 my java 阅读(1296) 评论(0)  编辑  收藏 所属分类: jsp

只有注册用户登录后才能发表评论。


网站导航: