页面一开始进去action,action负责把file文件夹下的所有文件读入一个ArrayList中
Action代码如下:
ArrayList list = new ArrayList();
String path=request.getRealPath("/")+"file";
String FullPath;
//System.out.println(path);
myDir=new File(path);
list.clear();
contents=myDir.listFiles();
for(int i=0;i
FullPath=contents[i].getName();
list.add(FullPath);
//System.out.println(FullPath);
}
request.setAttribute("list",list);
ActionForward forward=new ActionForward("/download.jsp");
return forward;
然后进入download.jsp中,这个页面主要负责把所有文件显示,并提供 下载连接,代码如下:
<%@ page language="java" contentType="text/html;charset=GBK" import="java.util.ArrayList"%>
<%ArrayList list=(ArrayList)request.getAttribute("list");
for(int i=0;i {
String a=java.net.URLEncoder.encode((String)list.get(i));
out.print(""+list.get(i)+"
");
}
%>