aspose file tools*
The moose likes Servlets and the fly likes Download problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Download problem" Watch "Download problem" New topic

Download problem

Monoj Roy
Ranch Hand

Joined: Oct 10, 2007
Posts: 98
I want to write a servlet that will pop up a window for save as file
as like we downlod file there opens a pop up . and save the file in local
file system

Following is the code .But this is not working ,Can anybody help.

response.setContentType("text/download"); //application/text
response.addHeader("content-disposition","attachment; filename=Exportar.txt"); //attachment

PrintWriter pw = response.getWriter();

Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2712

I am confused about what you are trying to do.
As far as downloading the file is concerned, I think only providing a hyperlink to it solves the problem.

Hope this helps .

|Asking Good Questions|
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Following is the code .But this is not working ,Can anybody help.

Its is always a good idea to tell us what is going wrong. Its easier to help that way.

Most probably, you want to write the response to the output stream rather than using a PrintWriter.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70

For your code snippet, I believe you should set the content type as "text/plain" (I don't think there is a "text/download"). You can google for the existing/valid content types.

Also, try setting the content disposition header as "Content-Disposition", with capital letters. The "attachment" part (opposed to "inline") should tell the browser to open the Save as dialog for you. Consider including quotes in your code if your file name might include blank spaces.
Monoj Roy
Ranch Hand

Joined: Oct 10, 2007
Posts: 98
Thanks it worked with test/plain
I agree. Here's the link:
subject: Download problem
Similar Threads
IE Mime type resolution?
How to fix the problem of need to click "Save" button TWICE on "File Download" popup?
Downloading from JSP
How to open popup window for "preview html"
How to provide download option on href link?