<%@page contentType="text/html;charset=gb2312"
import="java.sql.*"%>
<%!
int PageSize=2;
int ShowPage=1;
int RowCount=0;
int PageCount=0;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
public void jspInit()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:zxh","sa","");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery("SELECT * from oka");
rs.last();
RowCount=rs.getRow();
PageCount=((RowCount%PageSize)==0?(RowCount/PageSize):(RowCount/PageSize)+1);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
public void jspDestroy()
{
try{
rs.close();
stmt.close();
con.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
%><html>
<head>
<title>数据库</title>
</head>
<body>
<center>
<%
String ToPage=request.getParameter("ToPage");
if(ToPage!=null)
{
ShowPage=Integer.parseInt(ToPage);
if(ShowPage>PageCount)
{
ShowPage=PageCount;
}
else if(ShowPage<=0)
{
ShowPage=1;
}
}
rs.absolute((ShowPage-1)*PageSize+1);
%>
<h3>目前在第<font size=4 color=red>
<%=ShowPage%></font>页,共有
<font size=4 color=red>
<%=PageCount%></font>页</h3>
<%
for(int i=1;i<=PageSize;i++)
{
%>
<table border=1 bordercolor=royalblue bgcolor=lightblue>
<tr>
<td bgcolor=lightyellow width=100><b>实验序号</b></td>
<td width=100><b><%=rs.getString("实验序号")%></b></td>
<td bgcolor=lightyellow width=100><b>实验名称</b></td>
<td width=100><b><%=rs.getString("实验名称")%></b></td>
</tr>
</table>
<br>
<%
if(!rs.next())
break;
}
%>
<table>
<tr valign=baseline align=center>
<%
if(ShowPage!=1)
{
%>
<td width=150>
<a href= open.jsp?ToPage=<%=1%>>到第一页</a>
</td>
<td width=150>
<a href= open.jsp?ToPage=<%=ShowPage-1%>>到上一页</a>
</td>
<%
}
if(ShowPage!=PageCount)
{
%>
<td width=150>
<a href= open.jsp?ToPage=<%=ShowPage+1%>>到下一页</a>
</td>
<td width=150>
<a href= open.jsp?ToPage=<%=PageCount%>>到最后一页</a>
</td>
<%
}
%>
<td width=150>
<form action=open.jsp method=post>

<input type="text" name=ToPage style="height:20px;width:40px"
value=<%=ShowPage%>>页
</form>
</td>
</tr>
</table>
</center>
</body>
</html>