今天我问过你问题,但是效果好像不是我想要的那种,好像是纵向排列的,有点乱,所以务必再帮忙运行看一下,不甚感激.....我想要几行几列的效果(每行四五张,三四行这样),以下是我整理后的代码,注意总行数PageSize......谢
<body bgcolor="#c7f5d1" background="TU/tian.jpg">
<H2 align="right">
<font size=4 color="#9c9abd" face="楷体">-★- <a
href="bokeshouye.jsp">返回首页</a> </font>
</H2>
<%
Statement stmt = null;
ResultSet rs = null;
String strSQL = "";
int PageSize = 6; //每页显示的行数
int Page = 1; // 当前页码(当前显示页码)
int totalPage = 1; //总页数
int totalrecord = 0; //总记录数(总行数)
try {
shujuku conn = new shujuku();
//算出总行数
rs = conn.query("SELECt count(*) as id FROM Photo");
if (rs.next())
totalrecord = rs.getInt("id");
//输出记录
rs = conn.query("SELECt * FROM Photo");
if (totalrecord % PageSize == 0)// 如果是当前页码的整数倍
totalPage = totalrecord / PageSize;
else
// 如果最后还空余一页
totalPage = (int) Math.floor(totalrecord / PageSize) + 1;
if (totalPage == 0)
totalPage = 1;
if (request.getParameter("Page") == null
|| request.getParameter("Page").equals(""))
Page = 1;
else {
try {
Page = Integer.parseInt(request.getParameter("Page"));
} catch (java.lang.NumberFormatException e) {
// 捕获用户从浏览器地址拦直接输入Page=sdfsdfsdf所造成的异常
Page = 1;
}
}
if (Page < 1)
Page = 1;
if (Page > totalPage)
Page = totalPage;
rs.absolute((Page - 1) * PageSize + 1);
%>
<table WIDTH="590" HEIGHT="350" align="center" border=0 cellSpacing=0
cellPadding=5>
<%
for (int iPage =1; iPage <= PageSize; iPage++) {
if ((iPage - 1) % 2 == 0) { //if(iPage %4==0){
%>
<tr>
<%
}
%>
<td align="left" valign="top" bgcolor="#CCCCCC"
>
<center>
<img src="../upload/<%=rs.getString("image")%>" width="100"
height="100">
<br>
<a href='phchazhaopian1.jsp?name=<%=rs.getString("image")%>'><%=rs.getString("image")%>
</a>
</center>
</td>
<%
if ((iPage - 1) % 2 != 0) { //if(iPage !=0 && iPage%3 == 0){
%>
</tr>
<%
}
if (!rs.next())
break;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
%>
</table>
<br>
<br>
<br>
<br>
<FORM Action="phchazhaopian.jsp" Method="GET">
<center>
<%
if (Page != 1) {
out.print(" <A HREF=phchazhaopian.jsp?Page=1>第一页</A>");
out.print(" <A HREF=phchazhaopian.jsp?Page=" + (Page - 1)
+ ">上一页</A>");
}
if (Page != totalPage) {
out.print(" <A HREF=phchazhaopian.jsp?Page=" + (Page + 1)
+ ">下一页</A>");
out.print(" <A HREF=phchazhaopian.jsp?Page=" + totalPage
+ ">最后一页</A>");
}
%>
页数:
<font COLOR="Red"><%=Page%>/<%=totalPage%> </font>
</center>
</FORM>
</body>