jsp页面实现分页显示不正常
我的代码如下:
<%@ page language="java" contentType="text/html;charset=gb2312" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%@ page import="shop.javabean.DBConnection" %>
<jsp:useBean id="db" class="shop.javabean.DBConnection" ></jsp:useBean>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/shop.css"/>
<title>店铺列表</title>
</head>
<body bgcolor="#ffffff">
<table width="745" border="0" align="center">
<tr>
<td width="119" >店标</td>
<td width="251">店名</td>
<td width="83">主营产品</td>
<td width="63">访问人数</td>
<td width="63">开店日期</td>
</tr>
<%
String tdBgColor = "";
int num = 0;//控制单元格颜色
ResultSet rs = null;
String countRecord = "";
//sql2 = "select count(Remes_Id) from SReMessage where Mes_Id='"+Mes_Id+"' group by Mes_Id";
String sql0 = "select count(*) from Shop";
rs = db.executeQuery(sql0);
if(rs.next()){
countRecord = rs.getString(1);
}
String sql1 = "select Shop_Id,Shop_Name,Shop_Icon,Shop_MainPro,Shop_Visitors,Shop_OpenTime from Shop where Shop_State = 1 order by Shop_Visitors desc";
rs = db.executeQuery(sql1);
int number = 1;
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示的页码
String strPage;
int i;
intPageSize = 15; //设置一页的记录总数
strPage = request.getParameter("page"); //取得待显示的页码
if(strPage==null)
intPage = 1;
else
intPage=java.lang.Integer.parseInt(strPage); //将字符串转化为整型
if(intPage<1)
intPage = 1;
//rs.last(); // 获取记录总数
//intRowCount = rs.getRow();
intRowCount = Integer.parseInt(countRecord);
System.out.println("intRowCount="+intRowCount);
intPageCount = (intRowCount+intPageSize-1)/intPageSize;
if(intPage>intPageCount)
intPage = intPageCount;
if(intPageCount>0)
rs.absolute((intPage-1)*intPageSize+1); //将记录指针定位到待显示页的第一条记录上
i = 0;
try{
//以下部分为循环显示从数据库中读取出来的数据
while(i<intPageSize && !rs.isAfterLast()){
num++;
String Shop_Id = rs.getString("Shop_Id");
String Shop_Name = rs.getString("Shop_Name");//店名
String Shop_Icon = rs.getString("Shop_Icon");//店标
String Shop_MainPro = rs.getString("Shop_MainPro");//主营产品
String Shop_Visitors = rs.getString("Shop_Visitors");//访问人数
String Shop_OpenTime = rs.getString("Shop_OpenTime");//所在地
String time = Shop_OpenTime.substring(0,10);
System.out.println("ShopList.jspxxxxxxxxxShop_Id="+Shop_Id);
%>
<%
if(num%2==0){
tdBgColor="#FFFFF7";
}
else{
tdBgColor="#EEFAFF";
}
%>
<tr>
<td width="119" bgcolor="<%=tdBgColor %>"><a href="main.jsp?ShopId=<%=Shop_Id%>" target="_blank"><img src="<%=Shop_Icon %>" width="119" height="114" border="0" /></a></td>
<td width="251" bgcolor="<%=tdBgColor %>"><a href="main.jsp?ShopId=<%=Shop_Id%>" target="_blank"><%=Shop_Name %></a></td>
<td width="83" bgcolor="<%=tdBgColor %>"><%=Shop_MainPro %></td>
<td width="63" bgcolor="<%=tdBgColor %>"><%=Shop_Visitors %></td>
<td width="63" bgcolor="<%=tdBgColor %>"><%=time %></td>
</tr>
<%
rs.next();
}}catch(Exception e){
e.printStackTrace();
}finally{
rs.close();
db.closeDb();
}
%>
</table>
<form name="pageForm" action="ShopList.jsp" method="post">
<table align="right" width="745">
<tr>
<td>
共<%= intRowCount %>条记录,第<%=intPage %>/<%=intPageCount %>页
<%if(intPage<2){ %> 首页 | 上一页
<% }else{%> <a href="ShopList.jsp?page=1">首页</a>|<a href="ShopList.jsp?page=<%=intPage-1%>&">上一页</a>
<%}%>
<%if((intPageCount-intPage)<1){ %> 下一页 | 尾页
<%}else{%>
<a href="ShopList.jsp?page=<%=intPage+1%>"> 下一页</a> | <a href="ShopList.jsp?page=<%=intPageCount%>">尾页</a>
<%}%>
转到第<input type="text" name="page" size="3"/>页<input type="submit" value="Go" class="input1"/>
</td>
</tr>
</table>
</form>
</body>
</html>
数据库中有4条记录,每页显示15条,但是实际上只显示了第一条和最后一条记录出来;这是一种情况,还有一种情况就是设置每页显示1条记录,但是实际上却把所有的记录都罗列在首页。
不知道是什么原因,请高手指教!