我想允许我网站的最终用户从服务器下载文件, 我尝试使用2个jsp文件的经典方法:
index.jsp:
<a href="download.jsp">download the file</a>
download.jsp:
<%
String filename = "file.xls";
String filepath = "C:\\Files\\";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
%>
但是,它没有使用Fatwire 7.6.2中的2页模板, 那是因为我不允许在Fatwire中使用响应对象吗?
答案 0 :(得分:1)
在网站中使用响应对象(又名“fatwire”)确实不鼓励使用jsp。在站点中使文件可供下载的典型方法是对资产中的数据建模,然后使用blobserver标记来呈现URL。有关示例和其他类似标记,请参阅http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/render-getbloburl.html。
如果您不想将这些文件放入资源中,那么最好不要使用blobserver标记,只需通过网络服务器直接使用它们。
菲尔