主题:jsp 分页问题.
我想用下面这个程序实现分页显示:怎么打开很慢,而且几乎打不开,数据库重新启动一下就能打开,但是跳不到第二页,大家帮忙看看是程序问题还是数据库问题啊?程序如下:
guanli.jsp:
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>查询线路信息</title>
</head>
<body bgcolor="lightblue">
<jsp:useBean id="guanli" scope="page" class="SQLServer.SQLServer_dbconnect"/>
<p>
<hr>
<table align="center" border="1" >
<tr bgcolor="#eeeeee"><td>线路ID:</td><td>线路型号:</td><td>生产厂商:</td><td>额定温度:</td><td>前节点:</td><td>后节点:</td><td>所属机房</td></tr>
<%
String str=request.getParameter("Page");
String room_ID=(String)session.getAttribute("room_ID");
String sql="select * from line where room_ID='"+room_ID+"'";
ResultSet rs=guanli.executeQuery(sql);
if(str==null){str="0";}
int pagesize=10;
rs.last();
int RecordCount=rs.getRow();
rs.first();
int maxPage=0;
maxPage=(RecordCount%pagesize==0)?(RecordCount/pagesize):(RecordCount/pagesize+1);
int Page=Integer.parseInt(str);
if(Page<1){
Page=1;
}else if(Page>maxPage){
Page=maxPage;
}
rs.absolute((Page-1)*pagesize+1);
for(int i=0;i< pagesize;i++){
String lineid=rs.getString("lineid");
String type=rs.getString("type");
String pfactory=rs.getString("pfactory");
String temperature=rs.getString("temperature");
String linepre=rs.getString("linepre");
String linenext=rs.getString("linenext");
%>
<tr>
<td><%=lineid%></a></td>
<td><%=type%> </td>
<td><%=pfactory%> </td>
<td><%=temperature%> </td>
<td><%=linepre%> </td>
<td><%=linenext%> </td>
<td><%=room_ID%> </td>
</tr>
<% if(!rs.next()){ break;} }%></table>
<table width="100%" border=0>
<tr>
<td align="right">当前页数:[<%=Page%>/<%=maxPage%>]
<%if(Page>1){%>
<a href="guanli.jsp?Page=1">第一页 </a><a href="guanli.jsp?Page=<%=Page-1%>">上一页</a>
<%}
if(Page<maxPage){%>
<a href="guanli.jsp?Page=<%=Page+1%>">下一页 </a><a href="guanli.jsp?Page=<%=maxPage%>">最后一页 </a>
<%}%></td>
</tr>
</table>
</body>
</html>
guanli.jsp:
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>查询线路信息</title>
</head>
<body bgcolor="lightblue">
<jsp:useBean id="guanli" scope="page" class="SQLServer.SQLServer_dbconnect"/>
<p>
<hr>
<table align="center" border="1" >
<tr bgcolor="#eeeeee"><td>线路ID:</td><td>线路型号:</td><td>生产厂商:</td><td>额定温度:</td><td>前节点:</td><td>后节点:</td><td>所属机房</td></tr>
<%
String str=request.getParameter("Page");
String room_ID=(String)session.getAttribute("room_ID");
String sql="select * from line where room_ID='"+room_ID+"'";
ResultSet rs=guanli.executeQuery(sql);
if(str==null){str="0";}
int pagesize=10;
rs.last();
int RecordCount=rs.getRow();
rs.first();
int maxPage=0;
maxPage=(RecordCount%pagesize==0)?(RecordCount/pagesize):(RecordCount/pagesize+1);
int Page=Integer.parseInt(str);
if(Page<1){
Page=1;
}else if(Page>maxPage){
Page=maxPage;
}
rs.absolute((Page-1)*pagesize+1);
for(int i=0;i< pagesize;i++){
String lineid=rs.getString("lineid");
String type=rs.getString("type");
String pfactory=rs.getString("pfactory");
String temperature=rs.getString("temperature");
String linepre=rs.getString("linepre");
String linenext=rs.getString("linenext");
%>
<tr>
<td><%=lineid%></a></td>
<td><%=type%> </td>
<td><%=pfactory%> </td>
<td><%=temperature%> </td>
<td><%=linepre%> </td>
<td><%=linenext%> </td>
<td><%=room_ID%> </td>
</tr>
<% if(!rs.next()){ break;} }%></table>
<table width="100%" border=0>
<tr>
<td align="right">当前页数:[<%=Page%>/<%=maxPage%>]
<%if(Page>1){%>
<a href="guanli.jsp?Page=1">第一页 </a><a href="guanli.jsp?Page=<%=Page-1%>">上一页</a>
<%}
if(Page<maxPage){%>
<a href="guanli.jsp?Page=<%=Page+1%>">下一页 </a><a href="guanli.jsp?Page=<%=maxPage%>">最后一页 </a>
<%}%></td>
</tr>
</table>
</body>
</html>