求助:分页问题,单击“下一页”显示不了数据!
以下是我的代码:
单击“下一页”按钮时,提示“页面载入出错......,跳转不到指定页面!”
我用的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>
<td> WorkTime </td>
<td> IdleTime </td>
<td> TotalPeriods </td>
<td> Leaves </td>
</tr>
<%
i=0;
while(i <intPageSize&&!rs2.isAfterLast())
{
if(rs2.getBoolean( "Status "))
{
status = '开 ';
%>
<tr bgcolor= "red ">
<%
}
else
{
status = '关 ';
%>
<tr bgcolor= "cyan ">
<%
}
%>
<td> <div> <center> <%= rs2.getInt( "MotorNum ") %> </center> </div> </td>
<td> <div> <center> <%= rs2.getString( "MotorName ") %> </center> </div> </td>
<td> <div> <center> <%= status %> </center> </div> </td>
<td> <div> <center> <%= rs2.getInt( "WorkTime ") %> </center> </div> </td>
<td> <div> <center> <%= rs2.getInt( "IdleTime ") %> </center> </div> </td>
<td> <div> <center> <%= rs2.getInt( "TotalPeriods ") %> </center> </div> </td>
<td> <div> <center> <%= rs2.getInt( "Leaves ") %> </center> </div> </td>
</tr>
<%
rs2.next();
i++;
}
}
%>
</table>
<table width= "98% " border= "0 " cellpadding= "2 " cellspacing= "1 " class= "TableBody " align= "center ">
<tr>
<td height=22 colSpan=4 align= "right ">
第 <%=intPage%> 页/共 <%=intPageCount%> 页
<%
if(intPage!=1)
{
%>
<a href= "http://loacalhost:8080/MS/MainPage1.jsp?page= <%=intPage-1%> "> 上一页 </a>
<%
}
%>
<%
if(intPage!=intPageCount)
{
%>
<a href= "http://loacalhost:8080/MS/MainPage1.jsp?page= <%=intPage+1%> "> 下一页 </a>
<%
}
%>
请选择页码:
<select name= "page " onChange= "MM_jumpMenu( 'parent ',this,0) ">
<option value= "http://loacalhost:8080/MS/MainPage1.jsp?page= <%=intPage%> " selected > <%=intPage%> </option>
<%
int j;
for (j=1;j <=intPageCount;j++)
{
%>
<option value= "http://loacalhost:8080/MS/MainPage1.jsp?page= <%=j%> "> <%=j %> </option>
<%
}
%>
</select>
</td>
</tr>
</table>
<%
}
else
{
response.sendRedirect( "http://localhost:8080/MS/Error1.jsp ");
}
rs1.close();
stmt.close();
con.close();
}
else
{
%>
<p> 请输入用户名!
<%
}
%>
</center>
</body>
</html>
[解决办法]
MVC个多好
[解决办法]
首先要把错误代码贴出来
[解决办法]
是loacalhost还是localhost???
[解决办法]
<option value= "http://loacalhost:8080/MS/MainPage1.jsp?page= <%=j%> "> <%=j %> </option> 你把跳转连接定死了,你发布到网上去怎么办?
用
<a A HREF= "javascript:gotoPage( <%=nowPages+1%> ) "> 下一页 </a>
function gotoPage(pagenum){
this.form.pages.value = pagenum;
this.form.submit();
return ;
}