Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create an HTML form in JSP for downloading files?

 
Jeff Tanner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I understand how to create a form of type "multipart/form-data" that uploads a file from a client's box , but I am trying to use the same form code for downloading a file to a client's box .

Using the code below, the value of input named "downloadFileInput" should have "test.txt", but it is blank. If I try to use the "Browse" panel that pops up and provide it a file name of "test.txt", it returns a message that that file does not exist.

What is wrong with this HTML code within JSP file?



Thanks,
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand. If you want to download a file from the server, you just copy the file to the response. There isn't any HTML required to do that, only a link to something which will return the file as its response.

And preferably you wouldn't use a JSP to do that, since JSP is meant to generate HTML. If you're returning a file rather than an HTML page, you should use a servlet to return the file.

Or were you thinking that via this form, you could tell the browser where to put the file, so that the user wouldn't have to answer that question? Nope. That would be a serious security violation.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64845
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Form? For download?
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect this is for hacking reasons
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jhon masco wrote: I suspect this is for hacking reasons

I suspect not, because that doesn't make any sense.

Ultimately I think the OP is looking for a way to select a file from the server for download. But it's kind of hard to say. But as mentioned, form submissions go from the client to the server--nothing to do with downloading.

What precisely are you looking for? How to navigate files on the server?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic