新西兰地图中文版旅游:我的分页显示为什么错了啊

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 08:27:47
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.lang.Math.*"%>
<jsp:useBean id="aa" scope="session" class="vote.VoteConn"></jsp:useBean>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<%!
ResultSet rs=null;
ResultSet rsTmp=null;
String sql="";
int PageSize=6;
int Page=3;
int totalPage=1;
String str="";
public String ShowOnePage(ResultSet rs,int Page,int PageSize)
{
str="";
try
{
rs.absolute((Page-1)*PageSize+1);
}
catch(SQLException e){}
for(int iPage=1;iPage<=PageSize;iPage++)
{
str+=RsToGbook(rs);
try
{
if(!rs.next())break;
}
catch(Exception e){}

}
return str;
}
public String RsToGbook(ResultSet rs)
{
String tt="";
try
{
tt+="<tr>";
tt+="<td>"+rs.getString ("hw_name")+"</td>";
tt+="<td>"+rs.getString ("hw_cash")+"</td>";
tt+="<td>"+rs.getString ("hw_buys")+"</td>";
tt+="</tr>";
}catch(SQLException e){}
return tt;
}
%>
<%
String sql="select hw_name,hw_cash,hw_buys from hw where sort_id='25'";
try
{
rs=aa.executeQuery(sql);
}
catch(Exception e)
{out.println("cuo wu");}

%>
<body bgcolor="#99CC66">
<h2 align="center"></h2>
<hr>
<center>
<table border>
<tr bgcolor="#000099">
<th>chanpinmingzi</th>
<th>jisge</th>
<th>shuliang</th>
</tr>
<%
rsTmp=aa.executeQuery("select count(*) as mycount from hw");
rsTmp.next();
int totalrecord=rsTmp.getInt("mycount");
if(totalrecord % PageSize==0)totalPage=totalrecord/PageSize;
else totalPage=(int)Math.floor(totalrecord/PageSize)+1;
if(totalPage==0)totalPage=1;
rsTmp.close();
try
{
if(request.getParameter("Page")==null||request.getParameter("Page").equals(""))
Page=1;
else
Page=Integer.parseInt(request.getParameter("Page"));
}catch(java.lang.NumberFormatException e){out.println(e.toString());}
if(Page<1)Page=1;
if(Page>totalPage)Page=totalPage;
out.println(ShowOnePage(rs,Page,PageSize));
%>

</table>
<form action="fenyeshiyan.jsp" method="get">
<%
if(Page!=1)
{
out.println("<a href=fenyeshiyan.jsp?Page=1>第一页</a>");
out.println("<a href=fenyeshiyan.jsp?Page="+(Page-1)+">上一页</a>");
}
if(Page!=totalPage)
{
out.println("<a href=fenyeshiyan.jsp?Page="+(Page+1)+">下一页</a>");
out.println("<a href=fenyeshiyan.jsp?Page="+totalPage+">最后一页</a>");
}
rs.close();
%>
<p>输入页数<input type="text" name="Page" size="3">页数:<font color="#FF0000"><%=Page%>/<%=totalPage%></font>
</p>
</form>
</center>
<hr>
</body>
</html>

好长,晕,用DW测一下嘛