permaculture playing cards*
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
Author

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();
pw.println("Test");

pw.close();
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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 .


SCJP, SCWCD.
|Asking Good Questions|
Paul Sturrock
Bartender

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
Monoj,

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
 
Consider Paul's rocket mass heater.
 
subject: Download problem