aspose file tools*
The moose likes Servlets and the fly likes How to Specify the dynamic name for setting a file for downloading? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to Specify the dynamic name for setting a file for downloading?" Watch "How to Specify the dynamic name for setting a file for downloading?" New topic
Author

How to Specify the dynamic name for setting a file for downloading?

Varun Narang
Ranch Hand

Joined: Nov 19, 2004
Posts: 30
Hello everyone,
These days I am working on a project, and I am facing some problem in it. The thing is that I need to display some results as a result of the database query, and I need to provide a link so that user can download the file by clicking on it. I want to dynamically assign the file-name (as default) and the file I am retriving is from database it self. Can anyone help me with the solution of how to do this.
Thanks & Regards,
Varun Narang.


Your computer system is like AC, it's of no use when you open Windows ;)
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

There is a "Content-Disposition" header that allows you to send filename that you can allow your users to download.

It should be something like this -
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

where fileName is the dynamic filename that you want.
Do remember to set MIME type accordingly for the file.

HTH,
- Manish
Varun Narang
Ranch Hand

Joined: Nov 19, 2004
Posts: 30
Thanks Mr. Hatwalne,
That was a great help.
Thanks a lot once again.

In the mean time, I was playing with Initialization parameters, I found something really strange. It's about case-sensitivity of param-names. The case is as follows:
If in web.xml file of my application, while specifying <init-param> tag for Servlet, I specify string for <param-name> in INITCAP, I am not able to retrive the value of <param-value> when I use getServletConfig().getInitParameter("Initcap-word").
Is this a bug, or contradicting the conventions. Can anyone tell me about that?
Thanks in Advance,
Regards,
Varun Narang.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Specify the dynamic name for setting a file for downloading?