java 如何在jsp中获取上传文件的准确路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25863309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:49:21  来源:igfitidea点击:

How to get accurate path of the uploaded file in jsp?

javajsp

提问by KVK

I am trying to upload file from my local system using <INPUT NAME="file1" TYPE="file" >in jsp file.and i try to get actual path of the uploaded file with the file name. but i can't get correct path.

我正在尝试使用<INPUT NAME="file1" TYPE="file" >jsp文件从我的本地系统上传文件。我 尝试使用文件名获取上传文件的实际路径。但我无法获得正确的路径。

I am using the bellow code

我正在使用下面的代码

String filename = request.getParameter("file1");           

System.out.println(filename);
String r=  request.getRealPath(filename); 

Output : /home/raptor/vinoth/vinoth.k/apache-tomcat-7.0.50/wtpwebapps/LoginMonitor/file.txt instead of /home/raptor/vinoth/file.txt

输出:/home/raptor/vinoth/vinoth.k/apache-tomcat-7.0.50/wtpwebapps/LoginMonitor/file.txt 而不是 /home/raptor/vinoth/file.txt

Every time it search the file in my web application folder

每次它在我的 Web 应用程序文件夹中搜索文件时

but the about code not giving actual path. i am using firefox browser. can any one help me to fix this problem??

但是关于代码没有给出实际路径。我正在使用火狐浏览器。谁能帮我解决这个问题??

Thanks in advance

提前致谢

采纳答案by Ashay Patil

for what purpose you want to have real path? if you want it to upload/download on server.please refer this link http://www.javacodegeeks.com/2013/08/servlet-upload-file-and-download-file-example.html

为了什么目的,你想要真正的道路?如果您希望它在服务器上上传/下载。请参考此链接 http://www.javacodegeeks.com/2013/08/servlet-upload-file-and-download-file-example.html

this link contains a web application which has both operation for uploading and downloading a file from local system.

此链接包含一个 Web 应用程序,该应用程序具有从本地系统上传和下载文件的操作。