Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JSP下载多个文件_Java_Jsp - Fatal编程技术网

Java 使用JSP下载多个文件

Java 使用JSP下载多个文件,java,jsp,Java,Jsp,我需要从服务器下载文件。根据情况,我可能需要下载一个或多个文件 目前我只能下载一个文件。但是谁能帮我下载多个文件呢 我的代码: <%ArrayList grep=(ArrayList<String>)request.getAttribute("consoleOutputForSFTP"); ArrayList filename=new ArrayList<String>(); %> <br><%if(grep==null){ %>

我需要从服务器下载文件。根据情况,我可能需要下载一个或多个文件

目前我只能下载一个文件。但是谁能帮我下载多个文件呢

我的代码:

<%ArrayList grep=(ArrayList<String>)request.getAttribute("consoleOutputForSFTP");
ArrayList filename=new ArrayList<String>();
%>

<br><%if(grep==null){

 %>Awaiting Response from Server...<%}else{ %>

<%for(int i=0;i<grep.size();i++){ %>
<%if(grep.toArray()[i].toString().contains(".edr.out")) {%>

<%String[] downloadFileName=grep.toArray()[i].toString().split("/");
for(int j=0;j<downloadFileName.length;j++){
    if(downloadFileName[j].contains(".edr.out")){
         filename.add(downloadFileName[j]);
    }%>


<%} %>

<%  
    String filepath = "D:/DownloadedFiles/";   
      response.setContentType("APPLICATION/OCTET-STREAM");   
      for(int l=0;l<filename.size();l++){
          response.setHeader("Content-Disposition","attachment; filename=\"" + filename.toArray()[l].toString() + "\"");   



      java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename.toArray()[l].toString());  

      int k;   
      while ((k=fileInputStream.read()) != -1) {  
        out.write(k);   
      }   
      fileInputStream.close();

      }
    %>

<%=grep.toArray()[i].toString() %><br>

<%



} %>

<%=grep.toArray()[i].toString() %><br>


<%} }%>

</body>
</html>


正在等待服务器的响应。。。
如果>1,您需要创建并发送一个ZIP文件。您可以为每个文件提供单独的链接,也可以将其打包为ZIP文件。一个请求只有一个响应。@AlanHay您能告诉我如何从该zip部分开始吗。这对我会有很大帮助的!谢谢:)