-1

I uploaded new app on Jboss 7.

That app, amoung other things, can create file, save it and hopfully download it with html5 tag. After generated, the file saves on absolute path that I get from getServletContext().getRealPath("/");

By the server log I can tell that those actions done perfectly. The file is created and saved. The problem is with the download part.

I am trying to download the file with html5 tag. <a href=path+file name> download>Get Numbers!</a>

I am using exactly the same path that I used to save the file on the server and I keep getting that fail-no file error from Chrome.

Ideas?

Yu Zhang
  • 1,887
  • 5
  • 23
  • 36
Robokof
  • 29
  • 3
  • What is the actual URL being produced for that link? What is the server's response to the request? – David Jan 21 '16 at 19:52
  • The path for the saved file is "/opt/repo/versions/7.1/standalone/tmp/vfs/tempc56e386fb58c08a8/SlL.war-269016b5c31c942c/serial.xls, the Url for that Link is Get Numbers! – Robokof Jan 21 '16 at 19:56
  • And does your website *have* that path? That looks more like a file system path... – David Jan 21 '16 at 19:57
  • It have it. if not, i will get "java.io.FileNotFoundException: (No such file or directory)" when saving the file – Robokof Jan 21 '16 at 20:08
  • You wouldn't get a `FileNotFoundException` for a 404 error on a web server. I think you're confusing website URLs with file system paths. They are very different things. – David Jan 21 '16 at 20:10

1 Answers1

0

I am using exactly the same path that I used to save the file on the server

There's the problem. Your file path is something like this:

/opt/repo/versions/7.1/standalone/tmp/vfs/tempc56e386fb58c08a8/SlL.war-269‌​016b5c31c942c/serial.xls

That's fine on the server when getting the file from the file system. But that path means nothing to a web browser. The web browser is making a request to the web server for a file known to the web server.

So, for example, if your web server root is here:

/opt/mywebserver

Then that path ends up requesting this:

/opt/webserver/opt/repo/versions/7.1/standalone/tmp/vfs/tempc56e386fb58c08a8/SlL.war-269‌​016b5c31c942c/serial.xls

That file doesn't exist, so the web server responds with a 404 error.

You need to convert the file system path to a URL in order to use it in the markup. (And that path needs to be publicly visible to the web server, within its own path structure.)

David
  • 176,566
  • 33
  • 178
  • 245