aspose file tools*
The moose likes Servlets and the fly likes How do I download a file using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do I download a file using JSP" Watch "How do I download a file using JSP" New topic
Author

How do I download a file using JSP

Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
hello
Suooose i am displaying a list of file name in a JSP page and want that the user should be able to download the file as soon as he clicls on it how do i do it
Amit


<I>Chance Favours the Prepared minds"</I>
sudesai
Greenhorn

Joined: Mar 30, 2001
Posts: 7
Hi Amit,
You would need to trap that filename in a variable, and then use the java.io.FileInputStream to display its contents.

Hope this helps.
Regards,


Sandeep Desai <BR>[email]vgdesai@bom3.vsnl.net.in [/email]<BR><OL TYPE=1> <BR><LI><B>Sun Certified Java Programmer</B> <I>Scored 93 per cent </I><BR><LI><B>Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </B><I>Scored 56 out of 59 </I><BR><LI><B>IBM Enterprise Connectivity with J2EE </B><I> Scored 72 per cent </I><BR><LI><B>Enterprise Development on the Oracle Internet Platform </B><I> Scored 44 out of 56 </I><BR></OL>
sudesai
Greenhorn

Joined: Mar 30, 2001
Posts: 7
Hi Amit,
One more thing, that I owl like to mention.In case, your files are huge, then it would be advisable to use java.io.BufferedInputStream.
You just need to change the code to :

Hope this helps,
------------------
Sandeep Desai

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
Amy Hafer
Greenhorn

Joined: Mar 29, 2001
Posts: 6
In my case, reading and then writing the fileinputstream actually dumps a bunch of binary characters from the file to a new html page with a URL of the location of the servlet.
Has anyone else experienced this problem??
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Did you setup the response header properly? response.setContentType("application/pdf"); //Just an example
regds
maha anna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I download a file using JSP