jsp分页

ResultSet rs = conn.executeQuery("select * from tb_goods");
<table class="mainborder" valign="top" style="border-collapse: collapse;" background="images/leftnav_bg.gif"
border="0" cellpadding="0" cellspacing="0" width="183">
<tbody><tr><td><jsp:include page="left.jsp"/></td></tr></tbody>
</table>
</td>
<td class="centercontent"></td>
<td class="centercontent" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" valign="top" width="520">
<%if(!rs.next()){%>--判断数据集是否为空
<table width="100%" height="192" border="0" cellpadding="0" cellspacing="0">
  <tr>
   <td>No data</td>
  </tr>
</table>
<%}else{%>
<table width="100%" height="192" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<table width="100%" height="14" border="0" cellpadding="0" cellspacing="0">
  <tr>
  <td height="13" align="center">&nbsp;</td>
  </tr>
</table>
<table width="100%" height="48" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#CCCCCC" bordercolorlight="#FFFFFF">
<%String str=(String)request.getParameter("Page");//获取当前页数
if(str==null){
  str="0";
}
int pagesize=30;//每页显示的记录数
rs.last();//将指针移动到最后一行
int RecordCount=rs.getRow(); //获取记录集总数
int maxPage=0;
maxPage=(RecordCount%pagesize==0)?(RecordCount/pagesize):(RecordCount/pagesize+1);//求的最大的页数
int Page=Integer.parseInt(str);
if(Page<1){
  Page=1;
}else{
  if(Page>maxPage){
   Page=maxPage;
  }
}%>
<% int n = (Page-1)*pagesize+1;//求得记录集显示到第几条
rs.first();//将记录移动到第一条
for(int i=1;i<=10;i++){%>//显示10行
<tr style="padding:5px;">
<%
for(int j=1;j<=3;j++,n++){//显示3列
  if(!rs.next()){//判断记录集是否为空
  %><td>&nbsp;</td><%
  }else{
  rs.absolute(n);//将记录定位到地n条
  int sale_ID=rs.getInt(1);
  String s_goodsname=chStr.toChinese(rs.getString(2));
  float s_price=rs.getFloat(3);
  float s_nowprice=rs.getFloat(4);
  String s_picture=chStr.toChinese(rs.getString(5));
%>
<td width="32%" height="175" valign="top">
  <table width="100%"  border="0" cellpadding="0" cellspacing="0">
   <tr>
   <td height="95" align="center"><a href="goods_detail.jsp?ID=<%=sale_ID%>">
   <img src="images/goods/<%=s_picture%>" width="120" height="80" border="0"></a></td>
   </tr>
   <tr>
   <td height="20" align="center"><a href="goods_detail.jsp?ID=<%=sale_ID%>"><%=s_goodsname%></a></td>
   </tr>
   <tr>
   <td height="20" align="center" style="text-decoration:line-through;color:#FF0000">List Price $ <%=s_price%></td>
   </tr>
   <tr>
   <td height="20" align="center">Your Price $ <%=s_nowprice%></td>
   </tr>
   <tr>
   <td height="20" align="center">
   <%if (username!=null && username!=""){%>--判断用户是否登陆 如果登陆则可以添加到购物车
   <input type="image" src="images/buy.gif" name="see" class="btn_grey"
     />
   <%}%>
   </td>
   </tr>
  </table>
</td>
<%}}%>
</tr>
<%}%>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
   <td align="right">The current page:[<%=Page%>/<%=maxPage%>]&nbsp;
   <%if(Page>1){%>
   <a href="index.jsp?Page=1&i=1">The first page</a>&nbsp;&nbsp;<a href="index.jsp?Page=<%=Page-1%>">Previous</a>
   <%}if(Page<maxPage){%>
   <a href="index.jsp?Page=<%=Page+1%>">Next</a>&nbsp;&nbsp;<a href="index.jsp?Page=<%=maxPage%>">Finally one&nbsp;</a>
   <%}%>
   </td>
  </tr>
</table>
</td>
</tr>
</table>    
<%}%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值