IMAGE是我存放图片的文件夹。
我用下面的代码把他取了出来:
<table>
<%
String name = "";
String url = "";File d = new File("D:/Tomcat 5.0/webapps/ynx/image");
if (d.exists())
{
File list[]=d.listFiles();
for (int i = 0; i < list.length; i++)
{
if (list[i].isFile())
{ url = list[i].getPath();
name = list[i].getName();%><th>
<td>
<a href ="/ynx/image/<%=name%>">
<img src="<%=url%>"width="180" height="180 >
</a>
</td>
</th>
<tr>
<td>
<a href="http://localhost:8080/ynx/parent.html" onclick="javascript:localtion.self.close();"><%=name%>
</a>
</td>
</tr>
<%
}
}
} %>
</table>
郁闷的是,不知道怎么才能控制它在一个页面中只显示8张图片,如何实现他的分页功能。
急,请各位大侠帮忙解决一哈。感激不尽!在线等待!
我用下面的代码把他取了出来:
<table>
<%
String name = "";
String url = "";File d = new File("D:/Tomcat 5.0/webapps/ynx/image");
if (d.exists())
{
File list[]=d.listFiles();
for (int i = 0; i < list.length; i++)
{
if (list[i].isFile())
{ url = list[i].getPath();
name = list[i].getName();%><th>
<td>
<a href ="/ynx/image/<%=name%>">
<img src="<%=url%>"width="180" height="180 >
</a>
</td>
</th>
<tr>
<td>
<a href="http://localhost:8080/ynx/parent.html" onclick="javascript:localtion.self.close();"><%=name%>
</a>
</td>
</tr>
<%
}
}
} %>
</table>
郁闷的是,不知道怎么才能控制它在一个页面中只显示8张图片,如何实现他的分页功能。
急,请各位大侠帮忙解决一哈。感激不尽!在线等待!
{
List images =new ArrayList();
}else{
List images=(List)request.getAttribute("images");
}
for (int i = 0; i < list.length; i++)
{
name=list[i].getName();
images.add(name);
}
if(images.size()>8){
for(int i=0;i<8;i++){
out.println("<a href ="/ynx/image/'"+name+"'">
<img src="<%=url%>"width="180" height="180 ></a>");
for(int i=0;i<8;i++){
images.remove(i);
}
}
}
else
{
for(int i=0;i<images.size();i++){
out.println("<a href ="/ynx/image/'"+name+"'">
<img src="<%=url%>"width="180" height="180 ></a>");
}
for(int i=0;i<images.sizi();i++){
images.remove(i);
}
}
if(images.size()>0){
request.setAttribute("images",images);
}
大概就是这个思路了,你可以将name,url封装到一个对象中再放入List集合.
代码如下:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.io.*"%>
<html>
<head>
</head>
<body>
<%!
String name="";
String url = "";
%>
<table >
<tr><%
File d = new File("D:/Tomcat 5.0/webapps/ynx/image");
if (d.exists())
{
File list[]=d.listFiles();
String[] imagesName = new String[list.length];
String[] imagesUrl = new String[list.length];
for (int i = 0; i < list.length; i++)
{
if (list[i].isFile())
{ url = list[i].getPath();
name = list[i].getName();
imagesUrl[i] = url;
imagesName[i] = name;
%>
<td>
<img src="./ynx/image<%=imagesUrl[i]%>">
</td>
<% }
}
}
%>
</tr>
</table></body>
</html>