楼主,以下为JSP的我测试通过的!接分!!!!!!!!
<%
//----------------------分页------------------------------------------- //取记录总数
rs = stmt.executeQuery("SELECT count(*) as allRecord FROM news");
if(rs.next())
{
recordCount = rs.getInt("allRecord");
}
else
{
recordCount = 0;
}
rs.close(); //计算总页数
pageSize = recordCount / PAGE_SIZE;
if(pageSize * PAGE_SIZE < recordCount)
{
pageSize = pageSize + 1;
} //防止超出页数
if(intPage >= pageSize)
{
intPage = pageSize;
} //转到指定页
rs = stmt.executeQuery("SELECT IDEN,title FROM news order by IDEN DESC");
//当前记录
curRecord = (intPage - 1) * PAGE_SIZE + 1;
%>
<%
//----------------------分页------------------------------------------- //取记录总数
rs = stmt.executeQuery("SELECT count(*) as allRecord FROM news");
if(rs.next())
{
recordCount = rs.getInt("allRecord");
}
else
{
recordCount = 0;
}
rs.close(); //计算总页数
pageSize = recordCount / PAGE_SIZE;
if(pageSize * PAGE_SIZE < recordCount)
{
pageSize = pageSize + 1;
} //防止超出页数
if(intPage >= pageSize)
{
intPage = pageSize;
} //转到指定页
rs = stmt.executeQuery("SELECT IDEN,title FROM news order by IDEN DESC");
//当前记录
curRecord = (intPage - 1) * PAGE_SIZE + 1;
%>
int pageSize;
int RowCount;
int PageCount;
int intPage;
String strPage;
int i;
%>
<%
pageSize=5;
strPage=request.getParameter("page");
if(strPage==null){
intPage=1;
}else{
intPage=Integer.parseInt(strPage);
if(intPage<1) intPage=1;
}
%>
<html><%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String query="select * from bookinfo";
String ur2="jdbc:odbc:hello";
Connection con=DriverManager.getConnection(ur2,"shfree","123");
java.sql.Statement stm=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet res = stm.executeQuery(query); res.last();
RowCount=res.getRow();
PageCount=RowCount/pageSize;
if(intPage>PageCount) intPage=PageCount;
%>
<hr> <table align="center" width="622" height="1" border="1"><tr><td align=center width="102" height="1"><font face="华文中宋" size="3" color="#808080"><b>a</b></font></td> <td align=center width="213" height="1"><font face="华文中宋" size="3" color="#808080"><b>b</b></font></td>
<td align=center width="69" height="1"><font face="华文中宋" size="3" color="#808080"><b>c</b></font></td>
<td align=center width="196" height="1"><font face="华文中宋" size="3" color="#808080"><b>d</b></font></td> <td align=center width="91" height="1"><font face="华文中宋" size="3" color="#808080"><b>e</b></font></td>
</tr>
<%
if(PageCount>0){
res.absolute((intPage-1)*pageSize+1);
i=0;
while(i<pageSize&&!res.isAfterLast())
{
out.println("<tr>");
out.println("<th align=center width=\"102\" height=\"35\"><font face=\"华文中宋\" size=\"2\" color=\"#808080\"><b>"+res.getString("bookISBN")+"</b></font></th>");
out.println("<th align=center width=\"213\" height=\"35\"><font face=\"华文中宋\" size=\"2\" color=\"#808080\"><b>"+res.getString("bookNane")+"</b></font></th>");
out.println("<th align=center width=\"69\" height=\"35\"><font face=\"华文中宋\" size=\"2\" color=\"#808080\"><b>"+res.getString("bookAuthor")+"</b></font></th>");
out.println("<th align=center width=\"196\" height=\"35\"><font face=\"华文中宋\" size=\"2\" color=\"#808080\"><b>"+res.getString("publisher")+"</b></font></th>");
out.println("<th align=center width=\"91\" height=\"35\"><font face=\"华文中宋\" size=\"2\" color=\"#808080\"><b>"+res.getString("status")+"</b></font></th>");
out.println("</tr>");
res.next();
i++;
}
res.close();
stm.close();
con.close();
}
}catch(Exception e){
out.println(e);
}
%> </table>
<font face="华文中宋" size="4" color="#808080">第</font><%=intPage%><font face="华文中宋" size="4" color="#808080">页</font>
<font face="华文中宋" size="4" color="#808080">共</font><%=PageCount%><font face="华文中宋" size="4" color="#808080">页</font>
<%
if(intPage<PageCount){
%>
<a href="view_book1.jsp?page=<%=intPage+1%>"><font face="华文中宋" size="4" color="#808080">下一页</font></a>
<%
}
%>
<%
if(intPage>1){
%>
<a href="view_book1.jsp?page=<%=intPage-1%>"><font face="华文中宋" size="4" color="#808080">上一页</font></a>
<%
}
%><font face="华文中宋" size="4" color="#808080">请点击</font><a href="javascript:top.location.href='index.html'"><em><font face="华文中宋" size="4" color="#808080">这里</font> </em></A> <font face="华文中宋" size="4" color="#808080">返回</font>
</body>
<html> 这是可以实现的 可以运行
cn.Open "DSN=sms;UID=sa;PWD=1"
Set Rs = Server.CreateObject("ADODB.Recordset")
'magclass=Request.QueryString("class")
if 1=1 then
SqlStr = "select * from message order by sendnum desc"
Rs.Open SqlStr,cn,1,1
if not rs.eof then
Rs.pagesize=20
if request.QueryString("page")="" then
pageid="1"
else
pageid=Request.QueryString("page")
end if
num=pageid*Rs.pagesize-Rs.pagesize
Rs.absolutepage=pageid
if Rs.recordcount-pageid*Rs.pagesize+Rs.pagesize>Rs.pagesize then
pagenum=Rs.pagesize
pageend=0
else
pagenum=Rs.recordcount-pageid*Rs.pagesize+Rs.pagesize
pageend=1
end if
%>
<% for i = 1 to pagenum
num=num+1
if not rs.eof then
%>
<tr bgcolor="f7f7f7">
<td bgcolor="f7f7f7" align="center" width="8%" > <%=num%>
</td>
<td width="56%" bgcolor="f7f7f7" > <%=Rs("content")%> </td>
<td width="12%" bgcolor="f7f7f7" align="center"> <%=Rs("author")%> </td>
<td width="10%" align="center" > <%=Rs("sendnum")%> </td>
</tr>
<%
Rs.MoveNext
end if
next
'end if %>
我刚写的asp 可以的
要多少又多少
-------------------------------------------------------------------
pg=clng(request("page"))'设置一个存放页的变量
'此处链接你的数据库
if not rs.eof then
rs.pagesize=2'设置每页多少个记录
if request("page")="" then
pg=1
rs.absolutepage=1
else
rs.absolutepage=request("page")
end if
end if
'此处放你的其他程序
<%for i=1 to rs.pagesize
if rs.eof then
exit for
end if
%>
'此处放你的记录
<%rs.movenext
next
%>
----下面是分页
<form action=你的页面.asp method=post>'此表单为你在文本框输入页数,直接跳转
<td height="19" colspan="8" class="f">
<% if pg<1 then pg=1
if pg>rs.pagecount then pg=rs.pagecount
if pg<>1 then
response.write "[<a href=你的页面.asp?page=1>第一页</a>] "
response.write "[<a href=你的页面.asp?page="&(pg-1)&">上一页</a>] "
end if
if pg<>rs.pagecount then
response.write "[<a href=你的页面.asp?page="&(pg+1)&">下一页</a>] "
response.write "[<a href=你的页面.asp?page="&rs.pagecount&">最后一页</a>] "
end if
%>
输入页数:
<input size=3 name="page">
[记录共<font color=CE3100><%=rs.recordcount%></font>条/<font color=CE3100><%=rs.PageCount%></font>页/当前第<font color=CE3100><%=pg%></font>页]
</form>
我可以给你点关于实现分页的解决方案:
先做一个PageControl
public class PageControl {
public int curPage ; //当前是第几页
public int maxPage ; //一共有多少页------------>ok
public int maxRowCount ; //一共有多少行-------->ok
public int rowsPerPage ; //每页有多少行-------->set up
public String sql;
DBoperation db=new DBoperation();//--------------->这是一个自己做好的数据库操作的类
int startcount=rowsPerPage*(curPage-1);
public PageControl(String sql,int rowsPerPage,int curPage)
{
this.sql=sql;
this.rowsPerPage=rowsPerPage;
this.curPage=curPage;
this.maxRowCount=this.getmaxRowCount();
this.countMaxPage();
}
public int getmaxRowCount()
{
int row[]=new int[1];
row[0]=0;
db.executeQueryrowcount(sql,row,true);//----------------->一个方法用来计算需要数据的总行数
return row[0];
}
public void countMaxPage() //根据总行数计算总页数
{
if (this.maxRowCount % this.rowsPerPage==0)
{
this.maxPage = this.maxRowCount/this.rowsPerPage;
}
else
{
this.maxPage = this.maxRowCount/this.rowsPerPage + 1;
}
}
}
PageControl pageCtl = yourBusinessObject.listData(req.getParameter("jumpPage"));
req.setAttribute("pageCtl",pageCtl);
说明:yourBusinessObject封装了商业逻辑,是位于Business Logic Layer中的一个对象,
运用OOAD的方法,封装商业对象,在Persistent Layer之上组建坚实的Business Logic Layer 同样是构建大型电子商务。(这本分是IBM : developerWorks 中国网站的决绝方案)
觉得不错就摘抄了……继续 。。
<jsp:useBean id="pageCtl" class="yourpackage.PageControl" scope="request"></jsp:useBean><%if(pageCtl.maxPage!=1)){%><form name="PageForm" action="/servlet/yourpackage.yourservlet" method="post"><%@ include file="/yourpath/pageman.jsp"%> </form><%}%>
" ( select pkid, name,bz ,rownum row_no from "+
"( select ZGWMCHZDHD_PKID pkid , ZDHD_NAME name , ZDHD_VALID Bz from T2Q_0_ZGWMCHZDHD WHERE ZDHD_VALID = '1' ORDER BY ZGWMCHZDHD_PKID))"+
" Where row_no between "+ ((pages-1) * pageNum+1) +" And "+ (pages) * pageNum) ;
上面的ORACLE的,
其它的就得用游标来移动了,
加参数"int 页",数据库查询出该页的数据(需承担网络、数据库连接的费用);
二、检索出所有数据,分页,放入缓存中。(可与第一种方法搭配使用)
检索数据,按每页的长度分页,放入一个HASHMAP中(KEY对应页数,值存放当页的数据)
打开SESSION,将HASHMAP放入SESSION中,根据KEY值查找某页的数据(速度较快;需承担内存占用空间支出,数据量大时尤为突出);
三、打开游标,直接操作数据库(会一直占用该连接,连接过多时会出现问题)。数据库不同,操作不同,选择不同方式。
http://jsptags.com/index.jsp