Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I download a file using JSP

 
Amit Roy
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sudesai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

 
sudesai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you setup the response header properly? response.setContentType("application/pdf"); //Just an example
regds
maha anna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic