开发者

I cannot get the full physicial path of a selected file

I want full path of sele开发者_开发知识库cted file using GWT by using FileUpload. Can you help me?


There is no way to get file path from client side due to browser's security policy. You have to do it via a signed java applet or get it from your servlet.

fileUpload.getFilename may or may not return full path. Depends on the browser


You don't need it. Imagine that I am the client and you are the server. I give you the full file path "C:/My Documents/passwords.txt", how would you as being the server ever programmatically access the content of the file? With new File("C:/My Documents/passwords.txt") maybe? No, think logically about it, this ain't going to work as we both runs at physically different machines. The information about the full path is worthless.

The HTML file upload actually sends the content of the file from the client to the server, usually along with only the file name. You just need to grab the content as an InputStream by FileItem#getInputStream() or just to write it to disk directly by FileItem#write(). as per the FileUpload User Guide.

You can get the sole filename by FileItem#getName(), but some webbrowsers however sends the full client side disk file system path, such as Internet Explorer and Opera. This is wrong. You need to trim off the path by FilenameUtils#getName() as per the FileUpload FAQ.

(by the way, all code in blue is clickable and points to the Javadocs, I strongly recommend you to learn reading/interpreting it as well, they namely provide all information you need).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜