📄 1006224.xml
字号:
<?xml version='1.0' encoding='GB2312'?>
<?xml-stylesheet type='text/xsl' href='../csdn.xsl'?>
<Topic>
<Issue>
<PostUserNickName>Ha</PostUserNickName>
<rank>二级(初级)</rank>
<ranknum>user2</ranknum>
<credit>100</credit>
<TopicId>1006224</TopicId>
<TopicName>JSP数据库分页显示的问题</TopicName>
<PostUserId>201149</PostUserId>
<PostUserName>topmint</PostUserName>
<RoomName>JSP</RoomName>
<ReplyNum>8</ReplyNum>
<PostDateTime>2002-9-8 15:06:09</PostDateTime>
<Point>100</Point>
<ReadNum>0</ReadNum>
<RoomId>28</RoomId>
<EndState>2</EndState>
<Content>一个论坛(如CSDN)的帖子如何实现分页显示 
 表 id自增长</Content>
</Issue>
<Replys>
<Reply>
<PostUserNickName>zz</PostUserNickName>
<rank>五级(中级)</rank>
<ranknum>user5</ranknum>
<credit>92</credit>
<ReplyID>6483366</ReplyID>
<TopicID>1006224</TopicID>
<PostUserId>107094</PostUserId>
<PostUserName>zhu_liping</PostUserName>
<Point>0</Point>
<Content>利用JDBC很好实现呀
</Content>
<PostDateTime>2002-9-8 15:41:03</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>浅龙勿用</PostUserNickName>
<rank>三级(初级)</rank>
<ranknum>user3</ranknum>
<credit>100</credit>
<ReplyID>6483568</ReplyID>
<TopicID>1006224</TopicID>
<PostUserId>282705</PostUserId>
<PostUserName>trust_me</PostUserName>
<Point>30</Point>
<Content>作为参考:
<%@ page contentType="text/html;charset=8859_1" %> 
<% 
//变量声明 
java.sql.Connection sqlCon; //数据库连接对象 
java.sql.Statement sqlStmt; //SQL语句对象 
java.sql.ResultSet sqlRst; //结果集对象 
java.lang.String strCon; //数据库连接字符串 
java.lang.String strSQL; //SQL语句 
int intPageSize; //一页显示的记录数 
int intRowCount; //记录总数 
int intPageCount; //总页数 
int intPage; //待显示页码 
java.lang.String strPage; 
int i; 
//设置一页显示的记录数 
intPageSize = 2; 
//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//装载JDBC驱动程序 
java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); 
//设置数据库连接字符串 
strCon = "jdbc:oracle:thin:@linux:1521:ora4cweb"; 
//连接数据库 
sqlCon = java.sql.DriverManager.getConnection(strCon,"hzq","hzq"); 
//创建一个可以滚动的只读的SQL语句对象 
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); 
//准备SQL语句 
strSQL = "select name,age from test"; 
//执行SQL语句并获取结果集 
sqlRst = sqlStmt.executeQuery(strSQL); 
//获取记录总数 
sqlRst.last(); 
intRowCount = sqlRst.getRow(); 
//记算总页数 
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 
if(intPage>intPageCount) intPage = intPageCount; 
%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>JSP数据库操作例程 - 数据分页显示 - JDBC 2.0 - Oracle</title> 
</head> 
<body> 
<table border="1" cellspacing="0" cellpadding="0"> 
<tr> 
<th>姓名</th> 
<th>年龄</th> 
</tr> 
<% 
if(intPageCount>0){ 
//将记录指针定位到待显示页的第一条记录上 
sqlRst.absolute((intPage-1) * intPageSize + 1); 
//显示数据 
i = 0; 
while(i<intPageSize && !sqlRst.isAfterLast()){ 
%> 
<tr> 
<td><%=sqlRst.getString(1)%></td> 
<td><%=sqlRst.getString(2)%></td> 
</tr> 
<% 
sqlRst.next(); 
i++; 
} 
} 
%> 
</table> 
第<%=intPage%>页 共<%=intPageCount%>页 <%if(intPage<intPageCount){%><a href="jdbc20-oracle.jsp?page=<%=intPage+1%>">下一页</a><%}%> <%if(intPage>1){%><a href="jdbc20-oracle.jsp?page=<%=intPage-1%>">上一页</a><%}%> 
</body> 
</html> 
<% 
//关闭结果集 
sqlRst.close(); 
//关闭SQL语句对象 
sqlStmt.close(); 
//关闭数据库 
sqlCon.close(); 
%>
可以试试先!
祝你好运!
</Content>
<PostDateTime>2002-9-8 15:57:17</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>仨仁仕</PostUserNickName>
<rank>一星(中级)</rank>
<ranknum>star1</ranknum>
<credit>97</credit>
<ReplyID>6484277</ReplyID>
<TopicID>1006224</TopicID>
<PostUserId>204662</PostUserId>
<PostUserName>Reve</PostUserName>
<Point>30</Point>
<Content>也可以用jsp+xml+html来实现,下面给出一个saucer(思归)给的xml+html的分页例子,不妨参考一下:
<html>
<body>
<!--the following XML document is "stolen" from MSXML4 documentation-->
<xml id="xmldoc">
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious 
      agent known only as Oberon helps to create a new life 
      for the inhabitants of London. Sequel to Maeve 
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters, 
      battle one another for control of England. Sequel to 
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology 
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty 
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
</catalog>
</xml>
<table id="mytable" datasrc="#xmldoc" border="1" DATAPAGESIZE="2">
<thead><th>Title</th><th>Author</th><th>Genre</th><th>Publish Date</th><th>Price</th></thead>
<tbody><tr>
   <td><span datafld="title"></span></td>
   <td><span datafld="author"></span></td>
   <td><span datafld="genre"></span></td>
   <td><span datafld="publish_date"></span></td>
   <td><span datafld="price"></span></td>
 </tr>
</tbody>
</table>
<input type="button" value="previous page" onclick="mytable.previousPage()">
<input type="button" value="next  page" onclick="mytable.nextPage()">
</body>
</html>
</Content>
<PostDateTime>2002-9-8 16:53:48</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>jo_yoko</PostUserNickName>
<rank>四级(中级)</rank>
<ranknum>user4</ranknum>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -