简体   繁体   English

如何从Web应用程序获取本地计算机中文件的路径

[英]How to get path of a file in local machine from webapplication

I'm trying to upload a excel file from an application and trying to store the data in db and it is perfectly working in my system. 我正在尝试从应用程序上传excel文件,并试图将数据存储在db中,并且它在我的系统中运行良好。 But when im trying it from other machine I'm getting Error like path not found. 但是当我从其他机器上尝试时,我发现错误,例如找不到路径。

The reason for that error is known. 该错误的原因是已知的。 it's because the file path is belongs to the other system and the server(tomcat) is in my system. 这是因为文件路径属于另一个系统,而server(tomcat)在我的系统中。 when I passed that path as parameter server is searching in my system. 当我通过该路径作为参数服务器在我的系统中搜索时。

So here my question how to access the file from that system.? 所以这是我的问题,如何从该系统访问文件。

It sounds like you're passing your server a path on your machine. 听起来您要在服务器上传递服务器上的路径。 Since your server also runs on your machine it will find the file on your hard drive. 由于服务器也可以在计算机上运行,​​因此它将在硬盘上找到该文件。 However, when a user from another machine passes a path, your server will still try to look on your machine (since this is where it runs). 但是,当另一台计算机上的用户通过路径时,您的服务器仍会尝试在您的计算机上进行查找(因为这是它运行的位置)。

Your server will not be able to read the file on another machine (unless you have some file sharing stuff going on your local network). 您的服务器将无法读取另一台计算机上的文件(除非您的本地网络上有文件共享的内容)。

You'll need to add upload functionality to your server which can receive the actual file (not just the path to the file). 您需要向服务器添加可以接收实际文件(而不只是文件路径)的上传功能。

您需要从与您相关的网络中获取路径:

    File FileToRead = new File(new URI("file://MYSERVER/MYFOLDER/MYFOLDER/MYPICTURE.JPG"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用spring获取位于Web应用程序src文件夹中的文件的路径。 - Get the path of file located in src folder of webapplication using spring. 使用GlassFish的WebApplication中的文件路径 - file path in WebApplication using GlassFish Struts 2 Web应用程序中文件的相对路径 - relative Path for file in struts 2 Webapplication 使用Java从已部署的服务器(即我的webApplication)从用户本地计算机访问文件 - Accessing files from users local machine from deployed server (i.e. my webApplication) in java 如何在GWT中获取文件的自定义路径(用户本地路径) - How to get the custom path(user local path) for file in GWT 重命名war文件以更改Web应用程序的上下文路径 - Rename war file to change the context path of an webapplication 如何使用Java将文件从ftp服务器下载到本地计算机 - How to download a file from ftp server to local machine using java 获取资源的本地文件路径 - Get local file path of a ressource 使用jsp和servlet从本地驱动器获取文件路径 - get file path from local drive with jsp and servlet 我们如何使用Java从本地计算机打开远程计算机上存在的文件? - How can we open a file present on remote machine from local machine using java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM