我想在页面上输出每行四个图片,图片从固定文件夹中读取。以前用asp实现了,代码如下:
<%
Set  fso=server.createobject("scripting.filesystemobject")
Set  folder=fso.getfolder(server.mappath("album/small"))
c=1
For Each ii In folder.files 
ii=Mid(ii,InstrRev(ii,"\")+1)
%>
<% if right(ii,9)<>"Thumbs.db" then %>
                  <td height="175" bgcolor="f2f5f7"> <table width="175" border="0" align="left" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td width="175" height="175"> <table width="120" height="90" border="0" align="center" cellpadding="0" cellspacing="0" class="bk">
                          <tr> 
                            <td width="120" height="90" bgcolor="#FFFFFF"><a href="album/big/<%=Mid(ii,2)%>" target="_blank"><img src="album/small/<%=ii%>" width="120" height="90" border="0"></a></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table></td>
<%end if%>
<% If c Mod 4=0 Then response.write "</tr><tr>"
c=c+1
Next %>
希望可以用jsp实现。请教高手,谢谢

解决方案 »

  1.   

    <jsp:directive.page contentType="text/html; charset=GBK"/>
    <table border="0" cellpadding="0" cellspacing="0" width="300">
    <%
    java.io.File small = new java.io.File(application.getRealPath("/album/small"));
    java.io.File[] children = small.listFiles(new java.io.FilenameFilter() {// 取得 album/small 文件夹下的所有图像, 包括文件夹
    public boolean accept(java.io.File dir, String name) {
    name = name.toLowerCase();
    if(name.endsWith(".jpg") || name.endsWith("png") || name.endsWith("gif"))
    return true;
    return false;
    }
    });
    int index = 0;
    out.print("<tr>");
    for(int i = 0; children != null && i < children.length; i++) {
    if(children[i].isDirectory())
    continue;
    if(index++ % 4 == 0)
    out.print("</tr><tr>");
    out.print("<td width=\"120\" height=\"90\" bgcolor=\"#FFFFFF\"><a href=\"album/big/" + children[i].getName() + "\" target=\"_blank\"><img src=\"album/small/" + children[i].getName() + "\" width=\"120\" height=\"90\" border=\"0\"></a></td>");
    }
    out.print("</tr>");
    %>
    </table>
      

  2.   

    万分感谢 zhkl0228(凯子魅力) 的指导,但是不知什么原因没有实现效果,另外,我是新来的,可以告诉我如何给分吗?
      

  3.   

    谢谢,zhkl0228(凯子魅力) ,告诉我如何给分吧。