- 爱易网页
-
Java教程
- 分页有关问题,单击“下一页”显示不了数据
日期:2014-05-18 浏览次数:21001 次
求助:分页问题,单击“下一页”显示不了数据!
以下是我的代码:
单击“下一页”按钮时,提示“页面载入出错......,跳转不到指定页面!”
我用的fireforks浏览器!
<%@ page contentType= "text/html;charset=GB2312 " %>
<%@ page import= "java.sql.* " %>
<html>
<head>
<title> MainPage </title>
<script language= "javascript ">
function MM_jumpMenu(targ,selObj,restore)
{
eval(targ+ ".location= ' "+selObj.options[selObj.selectedIndex].value+ " ' ");
if(restore)
selObj.selectedIndex=0;
}
</script>
</head>
<body>
<%! char status; %>
<center>
<h1> <font color= "blue "> Motor Parameter Check System </font> </h1>
<hr>
<%
String username = request.getParameter( "txt1 ");
String password = request.getParameter( "txt2 ");
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
Connection con = DriverManager.getConnection( "jdbc:odbc:Motor ");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
if(username.length()!=0)
{
ResultSet rs1 = stmt.executeQuery( "Select * From MotorUser Where UserName= ' "+username+ " ' and Pwd= ' "+ password + " ' ");
if(rs1.next())
{
ResultSet rs2 = stmt.executeQuery( "Select * From MotorType Where 1=1 ");
%>
<p> <font size= "5 " color= "red "> <%= username %> ,欢迎登录! </font> </p>
<%
//分页显示
int intPageSize = 18; //每页的记录数
int intRowCount; //记录总数
int intPageCount; //页码总数
int intPage; //待显示页码
String strPage;
int i;
//取待显示页码
strPage = request.getParameter( "page ");
if(strPage==null)
{
intPage = 1;
}
else
{
intPage=Integer.parseInt(strPage);
if(intPage <1)
intPage=1;
}
rs2.last();
intRowCount = rs2.getRow();
//计算总页数
intPageCount = (intRowCount+intPageSize-1)/intPageSize;
//调整待显示的页码
if(intPage> intPageCount)
intPage=intPageCount;
if(intPageCount> 0)
{
//将记录指针定位到待显示页的第一条记录上
rs2.absolute((intPage-1)*intPageSize+1);
//显示数据
%>
<table bgcolor= "black ">
<tr bgcolor= "yellow ">
<td> MotorNumber </td>
<td> MotorName </td>
<td> Status </td>