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"> </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> </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%>]
<%if(Page>1){%>
<a href="index.jsp?Page=1&i=1">The first page</a> <a href="index.jsp?Page=<%=Page-1%>">Previous</a>
<%}if(Page<maxPage){%>
<a href="index.jsp?Page=<%=Page+1%>">Next</a> <a href="index.jsp?Page=<%=maxPage%>">Finally one </a>
<%}%>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%}%>
<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"> </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> </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%>]
<%if(Page>1){%>
<a href="index.jsp?Page=1&i=1">The first page</a> <a href="index.jsp?Page=<%=Page-1%>">Previous</a>
<%}if(Page<maxPage){%>
<a href="index.jsp?Page=<%=Page+1%>">Next</a> <a href="index.jsp?Page=<%=maxPage%>">Finally one </a>
<%}%>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%}%>
![](https://i-blog.csdnimg.cn/blog_migrate/7a9f8c2f833206445a63e9b8dc5b1286.gif)