aspose file tools*
The moose likes Servlets and the fly likes downloading a file. how can i set the file name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "downloading a file. how can i set the file name?" Watch "downloading a file. how can i set the file name?" New topic
Author

downloading a file. how can i set the file name?

Leonardo Penha
Ranch Hand

Joined: Feb 15, 2002
Posts: 68
I have a .zip file stored in my database in a BLOB field and I want my web site user to download this file when he/she clicks on a web page button. Here is what I do in my servlet:
response.setContentType("application/octet-stream");
byte[] b = /*get the BLOB field from my database*/
OutputStream out = response.getOutputStream();
out.write(b);
out.flush();
out.close();
When the user clicks on my web page button the above code is executed and my web browser prompts the user to download the file, but the dialog box displays the form action instead of the filename. The contents of the file are ok, but I want the user to be able to save the file with the same name as it is stored in the database.
Can anyone help me with this?
Att.
Leonardo Penha
P.S.: In my servlet I have the file name stored in a String variable.


Leonardo Penha<br />SCJP, SCJD, SCWCD, SCEA, SCMAD, SCDJWS
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
you need to set a Http Header called content disposition to set the file name which you can do as follows:
response.setHeader("Content-disposition", "inline;filename=<your filename here>"


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: downloading a file. how can i set the file name?
 
Similar Threads
Setting response header through Javascript
Enable/disable buttons - File download(CSV)
file download-user authentication-window close
Downloading file from server
Uploading file in a database