[英]How to read files on client local disk from server side code (JSP or Servlet)
I am writing a Web Project with Java. 我正在用Java编写一个Web项目。 I have the problems with reading files on client machine's local disk using Servlet. 使用Servlet读取客户端计算机本地磁盘上的文件时遇到问题。 When I directly run the following code in Eclipse, it runs well. 当我在Eclipse中直接运行以下代码时,它运行良好。 I can read the files on other client machine (Not on server machine). 我可以在其他客户端计算机(而不是服务器计算机)上读取文件。 But, when I make the project war file, put it on the Tomcat Server and run it, I cannot read the files. 但是,当我制作项目war文件时,将其放在Tomcat Server上并运行它,我无法读取这些文件。 Thanks for any hints and advice in advance. 感谢您的任何提示和建议。 My code is here: 我的代码在这里:
File file = new File("\\\\dell-nb\\SharedFile");
File[] list=file.listFiles();
for(int i=0;i<list.length;i++)
System.out.println(list[i].getName());
It is as 'designed', at best for security reasons. 出于安全考虑,它是“设计的”。 Imagine that any server can access any files in your computer. 想象一下,任何服务器都可以访问计算机中的任何文件。 You will not have any privacy. 您将没有任何隐私权。 The best way to transfert file from client to server is with an upload. 将文件从客户端传输到服务器的最佳方法是上传。 Search on the net on how to make an upload page in java. 在网上搜索如何在Java中制作上传页面。
Check this: http://commons.apache.org/proper/commons-fileupload/ and How to upload files to server using JSP/Servlet? 检查以下内容: http : //commons.apache.org/proper/commons-fileupload/以及如何使用JSP / Servlet将文件上传到服务器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.