Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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 使用ApachePOI使用ahref链接创建和下载excel文件_Java_Jsp_Servlets_Apache Poi - Fatal编程技术网

Java 使用ApachePOI使用ahref链接创建和下载excel文件

Java 使用ApachePOI使用ahref链接创建和下载excel文件,java,jsp,servlets,apache-poi,Java,Jsp,Servlets,Apache Poi,我在JSP页面上有一个excel文件列表,这些文件作为表存储在数据库中。它们是超链接。每当用户单击特定文件时,我都需要下载该文件 我有下面的代码 JSP页面 <html> <head> <title></title> </head> <body> <% List<String> encrypted = (List<String>)session.getAttribute("encry

我在JSP页面上有一个excel文件列表,这些文件作为表存储在数据库中。它们是超链接。每当用户单击特定文件时,我都需要下载该文件

我有下面的代码

JSP页面

<html>
<head>
    <title></title>
</head>
<body>
<%
  List<String> encrypted = (List<String>)session.getAttribute("encryptedlist");
  List<String> original = (List<String>)session.getAttribute("originallist");
  List<String> decrypted = (List<String>)session.getAttribute("decryptedlist");

%>

<table>
  <tr>
    <td style="font-weight: bold">Original Files</td>
    <td style="font-weight: bold">Encrypted Files</td>
    <td style="font-weight: bold">Decrypted Files</td>
  </tr>
  <%for(int i=0;i<size;i++) {%>
  <tr>
    <td><a href="DownloadServlet1?file=<%=original.get(i)%>"><%=original.get(i)%></a></td>
    <td><a href="DownloadServlet1?file=<%=encrypted.get(i)%>"><%=encrypted.get(i)%></a></td>
    <td><a href="DownloadServlet2?file=<%=decrypted.get(i)%>"><%=decrypted.get(i)%></a></td>
  </tr>
  <%}%>
</table>
</body>
</html> 

可能是什么问题?

将Excel文档直接写入HTTP响应:

wb.write(response.getOutputStream());
在服务器上本地保存Excel文档没有意义


另外,不要重定向到
Login.jsp
,这可能是导致错误的原因。

将Excel文档直接写入HTTP响应:

wb.write(response.getOutputStream());
在服务器上本地保存Excel文档没有意义


另外,不要重定向到
Login.jsp
,这可能是导致错误的原因。

在删除Login.jsp并使用wb.write(response.getOutpurStream())后,我会收到相同的错误;在删除Login.jsp和wb.write(response.getOutpurStream())之后,我得到了相同的错误;
wb.write(response.getOutputStream());