File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to create an HTML form in JSP for downloading files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to create an HTML form in JSP for downloading files?" Watch "How to create an HTML form in JSP for downloading files?" New topic
Author

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

Jeff Tanner
Greenhorn

Joined: Aug 09, 2010
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jan 10, 2002
Posts: 61218
    
  66

Form? For download?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jhon masco
Ranch Hand

Joined: May 13, 2010
Posts: 93
I suspect this is for hacking reasons
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create an HTML form in JSP for downloading files?