File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Force file download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Force file download" Watch "Force file download" New topic

Force file download

Arun Kumar
Ranch Hand

Joined: Jan 21, 2005
Posts: 133

I have to give the user an option to download a csv file I have created a link which points to this file in the server but when user clicks on the link rather than downloading the file the csv file is displayed in the browser

We are following FrontServlet Architecture hence Streaming the file as the response or response.setHeader is not working

please help
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

Hello Arun the bellow link will help you

Java Best Practices
Linux Best Practices
Amortization Calculator

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The key is that you need to set the content-disposition response header to "attachment".
I agree. Here's the link:
subject: Force file download
It's not a secret anymore!