<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*"%>
<% request.setCharacterEncoding("GBK"); %><%
try
{
String sql1="select * from book";
String sql2="select count(*) from book";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Books");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql1); Statement stmt2=conn.createStatement();
ResultSet rs2=stmt2.executeQuery(sql2);
rs2.next();
int pno=1;
int rowInpage=5;
int rowTotal=rs2.getInt(1);
int pageCount=rowTotal/rowInpage+1;
String s1=request.getParameter("pno");
if(s1!=null)
pno=Integer.parseInt(s1); if (pno<1)
pno=1;
if(pno>pageCount)
pno=pageCount; int start=rowInpage*(pno-1)+1;
int end=rowInpage*pno;
out.print("共有<font color=red>"+pageCount+"</font>页,");
out.print("当前是第<font color=red>"+pno+"</font>页");
%>
<center><table border="3" bgcolor="pink" width="80%">
<tr>
<th bgcolor="cyan">商品编号</th>
<th bgcolor="cyan">书名</th>
<th bgcolor="cyan">作者</th>
<th bgcolor="cyan">数量</th>
<th bgcolor="cyan">价格(/本)</th>
<th bgcolor="cyan">出版社</th>
</tr>
<% int i=1;
while(rs.next())
{
i++;
int bookId=rs.getInt(1);
String bookName=rs.getString(2);
String author=rs.getString(3);
int quantity=rs.getInt(4);
int price=rs.getInt(5);
String publisher=rs.getString(6); if(i<start)
continue;
if(i>end)
break; %>
<tr>
<td><center><%=bookId%></center></td>
<td><center><%=bookName%></center></td>
<td><center><%=author%></center></td>
<td><center><%=quantity%></center></td>
<td><center><%=price%></center></td>
<td><center><%=publisher%></center></td></tr> <% } %>
</table>
<a href="fenye.jsp?pno=1">第一页</a>
<a href="fenye.jsp?pno=<%=pno-1%>">上一页</a>
<a href="fenye.jsp?pno=<%=pno+1%>">下一页</a>
<a href="fenye.jsp?pno=<%=pageCount%>">最后一页</a>
<% }
catch(Exception e){e.printStackTrace();}%>可以照着你的情况修改
<%@ page import="java.sql.*"%>
<% request.setCharacterEncoding("GBK"); %><%
try
{
String sql1="select * from book";
String sql2="select count(*) from book";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Books");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql1); Statement stmt2=conn.createStatement();
ResultSet rs2=stmt2.executeQuery(sql2);
rs2.next();
int pno=1;
int rowInpage=5;
int rowTotal=rs2.getInt(1);
int pageCount=rowTotal/rowInpage+1;
String s1=request.getParameter("pno");
if(s1!=null)
pno=Integer.parseInt(s1); if (pno<1)
pno=1;
if(pno>pageCount)
pno=pageCount; int start=rowInpage*(pno-1)+1;
int end=rowInpage*pno;
out.print("共有<font color=red>"+pageCount+"</font>页,");
out.print("当前是第<font color=red>"+pno+"</font>页");
%>
<center><table border="3" bgcolor="pink" width="80%">
<tr>
<th bgcolor="cyan">商品编号</th>
<th bgcolor="cyan">书名</th>
<th bgcolor="cyan">作者</th>
<th bgcolor="cyan">数量</th>
<th bgcolor="cyan">价格(/本)</th>
<th bgcolor="cyan">出版社</th>
</tr>
<% int i=1;
while(rs.next())
{
i++;
int bookId=rs.getInt(1);
String bookName=rs.getString(2);
String author=rs.getString(3);
int quantity=rs.getInt(4);
int price=rs.getInt(5);
String publisher=rs.getString(6); if(i<start)
continue;
if(i>end)
break; %>
<tr>
<td><center><%=bookId%></center></td>
<td><center><%=bookName%></center></td>
<td><center><%=author%></center></td>
<td><center><%=quantity%></center></td>
<td><center><%=price%></center></td>
<td><center><%=publisher%></center></td></tr> <% } %>
</table>
<a href="fenye.jsp?pno=1">第一页</a>
<a href="fenye.jsp?pno=<%=pno-1%>">上一页</a>
<a href="fenye.jsp?pno=<%=pno+1%>">下一页</a>
<a href="fenye.jsp?pno=<%=pageCount%>">最后一页</a>
<% }
catch(Exception e){e.printStackTrace();}%>可以照着你的情况修改
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货