简体   繁体   中英

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. Please suggest....

This is webbrowser specific. Actually, MSIE is doing it wrong. As per the HTTP specification, the webbrowser should only send the filename along, not the full client side path. 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. 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). You should be getting the file contents as InputStream by FormFile#getInputStream() and then write it to an OutputStream of a temporary file. Or maybe the POI API is itself already accepting an InputStream directly, you could then just pass it along.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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