File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Downloading a file from database using Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Downloading a file from database using Struts" Watch "Downloading a file from database using Struts" New topic
Author

Downloading a file from database using Struts

archimedes ancient
Greenhorn

Joined: Jan 05, 2008
Posts: 2
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

Joined: Oct 16, 2006
Posts: 85
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

Joined: Sep 17, 2012
Posts: 4
Hi this is very useful. thank you so much.
Manusha Nadendla
Greenhorn

Joined: Sep 17, 2012
Posts: 4
Manusha Nadendla wrote:Hi this is very useful. thank you soo much.
 
Consider Paul's rocket mass heater.
 
subject: Downloading a file from database using Struts