简体   繁体   English

如何从服务器端代码(JSP或Servlet)读取客户端本地磁盘上的文件

[英]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.

相关问题 我如何使用jsp servlet从服务器端将Excel文件下载到客户端 - how can i download an excel file from server side to client side using jsp servlet 如何从Servlet运行套接字服务器/客户端,以便更好地访问项目代码和文件,从而更好地访问Tomcat服务器? - How to run socket server/client from a servlet to give better access on project code and files to Tomcat Server? 如何从servlet读取数据并将数据传递到JSP - How to read and pass data from servlet to JSP 如何将响应从servlet发送到客户端? - How to send response from servlet to client side? 如何将json对象从jsp页面的jsp部分传递到javascript部分,即从服务器端到客户端? - How to pass a json object from the jsp part of a jsp page to the javascript part i.e from server side to client side? 如何在服务器端使用jsp在客户端运行applet - how to run the applet on client side using jsp in server side 从jsp页面映射servlet时如何重用servlet中的代码 - How to reuse the code in servlet when mapping servlet from the jsp page 如何在Java客户端中读取servlet的响应? - How to read in a Java client a response from servlet? 如何从客户端Java代码衡量servlet方法的执行时间? - How to measure the execution time of a servlet's method from client side java code? 如何使用 JSP/Servlet 将文件上传到服务器? - How can I upload files to a server using JSP/Servlet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM