永发信息网

急救!jsp页面从数据库提出的照片怎样两行四列排列

答案:2  悬赏:40  手机版
解决时间 2021-07-20 10:59
  • 提问者网友:黑米和小志
  • 2021-07-19 13:03
各位高人,请求一个棘手问题,跪求,急!!!!
下面是一个我的上传照片(连接数据库)的显示页面(两个table之间)的代码,但是更改for循环之后,任然只能一行四列排列,请问怎么样能排出两行四列的效果,或者更多.......谢谢

<body bgcolor="#aaad8b" background="TU/tian.jpg">


<H2 align="right">
<font size=4 color="#9c9abd" face="楷体">-★-&nbsp; <a href="bokeshouye.jsp">返回首页</a>
</font>
</H2>


<%
Statement stmt = null;
ResultSet rs = null;
String strSQL = "";
int PageSize = 4; //每页显示的行数
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>

<tr><%
for (int iPage = 1; iPage <= PageSize; iPage++) {
%>
td align="left" valign="top" bgcolor="#CCCCCC"
style="filter: alpha(opacity =90)">

<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 (!rs.next())
break;
}

} catch (SQLException e) {
System.out.println(e.getMessage());
}
%>
</tr>

</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>
</html>

最佳答案
  • 五星知识达人网友:爱难随人意
  • 2021-07-19 14:24

关键部分


<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) {
%>
<tr>
<%
}
%>
<td align="left" valign="top" bgcolor="#CCCCCC"
style="filter: alpha(opacity = 90)">


<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) {
%>
</tr>
<%
}
if (!rs.next())
break;
}


} catch (SQLException e) {
System.out.println(e.getMessage());
}
%>



</table>

全部回答
  • 1楼网友:西岸风
  • 2021-07-19 14:37

哦,那好像是纵向的排列了,不知道你有没有运行,效果好像不是想象的那样,我追求类似于下面这种效果

* * * * * * * * * * *

* * * * * * * * * * *

* * * * * * * * * * *

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯