This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Downloading a file from database using Struts

 
archimedes ancient
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,

I am uploading a file into database which I don't know the extension. While retrieving from database, what content type should I mention in my jsp to provide download feature from database. I can get source code for it.

Thanks in advance.
 
Satish Kumar
Ranch Hand
Posts: 85
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while uploading store the contenttype and filename in some columns in database.
if your filename doesnt contain extn then while download you will see "file unknown type" in download window.

below are the steps for download

1)set contentlength in response
response.setContentLength(sizeoffile);
2)set the content type and header
response.setContentType(mimetypeofile);
response.setHeader("Content-disposition", "attachment; filename="
+ filename);
3)get a outputstream from HttpServletResponse and then write the binary data into it.
ServletOutputStream os = response.getOutputStream();
os.write(filecontent);
4)return null from execute() method.

you will get a popup showing the file.
 
Manusha Nadendla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi this is very useful. thank you so much.
 
Manusha Nadendla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manusha Nadendla wrote:Hi this is very useful. thank you soo much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic