Iframe的妙用!

    近日写一段程序,要求从数据库表中读出纪录,每个纪录对应硬盘上的文件,这些文件全部是gif和swf文件,要求将这些gif和swf文件已4*4没页16个的形式显示在浏览器上,就像ACDSee那样。
    由于数据库中的纪录是混乱的,gif和swf的排列顺序没有规则。对于gif文件,很好说,直接用<img src=<%=path%>>就可以显示出来,可是对于swf文件,就很麻烦,因为swf文件要在页面上显示的话,就要用到<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="/download/swflash.cab#version=5,0,0,0" width="480" height="400">
        <param name=movie value="images/man.swf">
        <param name=quality value=high>
        <embed src="images/man.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="480" height="400">
        </embed>

这么长的代码非常讨厌,因此,我想到了一个很方便的方法:就是用iframe:
<iframe src=<%=Url%> scroll=auto marginwidth=0 marginheight=0 height=80% width=80% frameborder=0></iframe>

程序代码如下:

<%
String sqlStr;
String imgUrl;
String extendName;
ResultSet rs=null;
pageBean.setPageSize(PAGESIZE);
pageBean.setCurrentPage(request);

dbBean.connectIntranetDatabase();
pageBean.setDB(dbBean);
sqlStr="select * from datamanager.res_animation_a where publish=1 order by id desc";
rs=pageBean.page(sqlStr);

int count=0;
%>

  <table border=1 cellpadding=0  cellspacing=0 bordercolorlight='#666666' width=95% align=center class='font-default' bordercolordark='#FFFFFF' >

<%
if(rs!=null){
  do
  {
    //显示字段内容
    out.println("<tr>");
    imgUrl=rs.getString("path");
    extendName=rs.getString("filetype");
    out.print("<td width=25% align=center valign=middle >");
    if (extendName.trim().equals("gif")){
      out.print("<a href=");
      out.print(imgUrl);
      out.print(">");
      out.print("<img width='100' border=0 src=" + imgUrl + ">");
      out.print("</a>");
    }else{
      out.print("<iframe src=");
      out.print(imgUrl);
      out.print(" scroll=auto marginwidth=0 marginheight=0 height=80% width=80% frameborder=0>");
      out.print("</iframe>");
    }
    out.print("<br>");
    out.print("<input type='checkbox' value='-1' name='");
    out.print(rs.getString("id"));
    out.print("'>");
    out.print(rs.getString("name"));
    out.print(".");
    out.print(rs.getString("filetype"));
    out.println("</td>");
    count++;

    out.print("<td width=25% align=center valign=middle >");
    if (rs.next()){
      imgUrl=rs.getString("path");
      extendName=rs.getString("filetype");
      if (extendName.trim().equals("gif")){
        out.print("<a href=");
        out.print(imgUrl);
        out.print(">");
        out.print("<img width='100' border=0 src=" + imgUrl + ">");
        out.print("</a>");
      }else{
        out.print("<iframe src=");
        out.print(imgUrl);
        out.print(" scroll=auto marginwidth=0 marginheight=0 height=80% width=80% frameborder=0>");
        out.print("</iframe>");
      }
      out.print("<br>");
      out.print("<input type='checkbox' value='-1' name='");
      out.print(rs.getString("id"));
      out.print("'>");
      out.print(rs.getString("name"));
      out.print(".");
      out.print(rs.getString("filetype"));
      count++;
    }
    else{
        out.print(" ");
    }
    out.println("</td>");

    out.print("<td width=25% align=center valign=middle >");
    if (rs.next()){
      imgUrl=rs.getString("path");
      extendName=rs.getString("filetype");
      if (extendName.trim().equals("gif")){
        out.print("<a href=");
        out.print(imgUrl);
        out.print(">");
        out.print("<img width='100' border=0 src=" + imgUrl + ">");
        out.print("</a>");
      }else{
        out.print("<iframe src=");
        out.print(imgUrl);
        out.print(" scroll=auto marginwidth=0 marginheight=0 height=80% width=80% frameborder=0>");
        out.print("</iframe>");
      }
      out.print("<br>");
      out.print("<input type='checkbox' value='-1' name='");
      out.print(rs.getString("id"));
      out.print("'>");
      out.print(rs.getString("name"));
      out.print(".");
      out.print(rs.getString("filetype"));
      count++;
    }
    else{
        out.print(" ");
    }
    out.println("</td>");

    out.print("<td width=25% align=center valign=middle >");
    if (rs.next()){
            imgUrl=rs.getString("path");
            extendName=rs.getString("filetype");
        out.print("<a href=");
        out.print(imgUrl);
        out.print(">");
        out.print("<img width='100' border=0 src=" + imgUrl + ">");
        out.print("</a>");

        out.print("<br>");
        out.print("<input type='checkbox' value='-1' name='");
        out.print(rs.getString("id"));
        out.print("'>");
        out.print(rs.getString("name"));
        out.print(".");
        out.print(rs.getString("filetype"));
        count++;
    }
    else{
        out.print(" ");
    }
    out.println("</td>");


    out.println("</tr>");

  }while(rs.next() && count<PAGESIZE);
}
%>
</table>
300*300
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00575 秒