简体   繁体   English

在struts中使用FormFile时如何获取完整的文件路径?

[英]How to get the full file path while using FormFile in struts?

Without uploading a xls file I want to read the data from xls file using POI API.For that I need the full file path with file name.IE gives the full file path where as Mozzila does not.Is there any alternate way to get the full file path. 没有上载xls文件,我想使用POI API从xls文件中读取数据。为此,我需要带有文件名的完整文件路径.IE给出了完整的文件路径,而Mozzila却没有。完整的文件路径。 Please suggest.... 请建议....

This is webbrowser specific. 这是特定于Web浏览器的。 Actually, MSIE is doing it wrong. 实际上,MSIE做错了。 As per the HTTP specification, the webbrowser should only send the filename along, not the full client side path. 根据HTTP规范,Web浏览器应仅发送文件名,而不发送完整的客户端路径。 You're supposed to trim off the full path from the filename, if any present. 您应该删掉文件名中的完整路径(如果有)。 Eg 例如

filename = filename.substring(filename.lastIndexOf('/') + 1);

Even then, what's the value of knowing the full file path in the server side? 即使这样,知道服务器端的完整文件路径有什么价值? This information is valueless. 此信息是无价的。 If your intent is to get a handle of the file using java.io.File , then you're doing it wrong. 如果您打算使用java.io.File来获取文件的句柄,那么您做错了。 The server don't have direct access to the client's local disk file system (unless the webbrowser and webserver runs both at the physically same machine). 服务器无法直接访问客户端的本地磁盘文件系统(除非Web浏览器和Web服务器都在物理上相同的计算机上运行)。 You should be getting the file contents as InputStream by FormFile#getInputStream() and then write it to an OutputStream of a temporary file. 您应该通过FormFile#getInputStream()将文件内容作为InputStream FormFile#getInputStream() ,然后将其写入临时文件的OutputStream Or maybe the POI API is itself already accepting an InputStream directly, you could then just pass it along. 或者,也许POI API本身已经直接接受InputStream ,然后可以将其传递。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM