很多研究和努力工作但仍未获得解决方案。我有一个Web应用程序托管在公司服务器上,我在tomcat上运行我的tomcat和web应用程序。我无法下载特定文件夹中位于服务器上的文件。
下面的JSP代码
<%@ page language="java" contentType="text\html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.io.File,java.io.IOException,java.util.*,java.io.*,java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<meta http-equiv="Content-Type" content="text\html; charset=ISO-8859-1">
<script type="text/javascript">
function downloadPDF(_var)
{
var docLocation = "path same as given below of variable 'filename'"+_var;
window.open(docLocation,"resizeable,scrollbar");
}
</script>
</head>
<body>
<%
String filename = "path of folder on server outside of tomcat directory(i.e outside of project foler)";
File f = new File(filename); // current directory
File[] files = f.listFiles();
for (File file : files) {
if (file.isDirectory()) {
//System.out.print("directory:");
} else {
%>
<a href="#" target="" onclick="downloadPDF('<%=file.getName()%>')"><br><%= file.getName()+"_"+currentDate%></a>
<%
}
}
%>
</body>
</html>