【发布时间】:2014-12-18 05:50:20
【问题描述】:
这是jsp文件上传表单
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>File Uploading form</title>
</head>
<body>
<form action="./read.do" method="post">
Select the file to read: <input type="file" id="myFile" size="50">
<br />
path is: <input type="text" name="path" />
<button type="button" onclick="myFunction()">Copy path</button>
<input type="submit" value="Submit">
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myFile").value;
document.getElementsByTagName("INPUT")[3].setAttribute("value",x);
}
</script>
</form>
</body>
</html>
这里我没有将文件上传到我的服务器,我只是获取文件的路径并使用 servlet 中的以下代码读取文件
String path = req.getParameter("path");
FileInputStream fis = null;
File excel = new File(path);
fis = new FileInputStream(excel);
当我在存在服务器的同一台机器上运行时,这工作正常。但是当我尝试从其他机器访问时,代码正在搜索我机器中的路径,而不是在客户端机器上如何解决这个问题。 我已经看到了其他一些方法,例如使用 multipart ,但是文件正在加载到服务器,但出于我的要求,我不应该将文件直接上传到我的服务器,我必须通过获取文件路径自行读取客户端计算机上的完整文件。请建议我一些想法来实现这一目标
【问题讨论】:
标签: java jsp servlets multipart