This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Download problem

 
Monoj Roy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it worked with test/plain
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic