最簡(jiǎn)單的JSP分頁(yè)實(shí)現(xiàn)!
<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;//總頁(yè)數(shù)
int intRowCount;//總記錄
int intPageSize;//每頁(yè)顯示記錄數(shù)
int intPage;//當(dāng)前頁(yè)
int intNext;//下一頁(yè)
int intPrev;//上一頁(yè)
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%> 頁(yè) 每頁(yè)顯示 <%=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 閱讀(1301)
評(píng)論(0) 編輯 收藏 所屬分類:
jsp