Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Force the browser to display the Save dialog box  RSS feed

 
akshay pandit
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a text stored in a OutPut Stream. Now i want to show a download window to download that text from browser or force the browser to display the Save dialog box.
Please suggest how to achieve this.
Its really urgent
Thanks
Akshay
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a text stored in a OutPut Stream

You mean in some sort of a Java program, you have this. The answer depends somewhat on precisely what sort of program it is. If it's a servlet, then just sending the data along as a result would be fine; if you definitely want to force a download, as opposed to displaying the data as a page, then you could use the mime type "application/octet-stream".
If it's not a servlet, then we really can't answer the question without more information from you about what exactly you're doing.
 
akshay pandit
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah it is a java program.
I am converting XML document object inte Text format using XSL.
Now i can create text file but i dont want to do that
rather want to download that converted data.
The problem is what should be the parameter in FileOutputStream
i dont want to save file on server.
please suggest.
The steps which i m using are as follows :-
javax.xml.transform.Source source = new DOMSource(doc);
java.io.OutputStream os = new java.io.FileOutputStream("What to Pass Here");

String filename = "sample.txt";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
javax.xml.transform.Result result = new StreamResult(os);

Transformer trans;
TransformerFactory factory = TransformerFactory.newInstance();
trans = factory.newTransformer(new StreamSource(xlsPath));
trans.transform(source,result);
Download box is coming up but when i save the file it contains blank file.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why you're using a FileOutputStream if you want to send the data back to the browser -- use the stream you get back from response.getOutputStream().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!