File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Stream file to client that exists only in memory? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Stream file to client that exists only in memory?" Watch "Stream file to client that exists only in memory?" New topic
Author

Stream file to client that exists only in memory?

Rob Hyx
Greenhorn

Joined: Nov 12, 2008
Posts: 14
I have the contents of a file that I have constructed in memory by basically using String.getBytes(); and then passing that into a ByteArrayInputStream. I then read the bytes and stream them out via ServletOutputStream. The text reaches the client because I see the response in Firebug, the only problem is, is that it's not a file. I set the response like:



The call is made asynchronously. Any idea what I am doing wrong? I want there to be a prompt for the user to either save or open the file in the appropriate application.

Thanks in advance!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

A response is a response; it's never a file. You've set the content disposition to tell the browser your intentions. What happens then is usually up to the browser and/or the user's settings.

Have you tried it in different browsers to observe the behavior?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

P.S. The fact that the response data originally existed only in memory is completely moot. The browser has no idea how the data originated and couldn't care less.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stream file to client that exists only in memory?
 
Similar Threads
very urgent...plz help
Zip and excel generated on the fly
How to write the content from document file to jsp page
How to implement file downloading functionality ?
How to respond to the client in PDF format to the client from Servlet?