aspose file tools*
The moose likes Struts and the fly likes write html from byte[] to response.getOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "write html from byte[] to response.getOutputStream" Watch "write html from byte[] to response.getOutputStream" New topic
Author

write html from byte[] to response.getOutputStream

John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
Hello,

I have a question regarding how to write html to an OutputStream from a byte[] array. I have the following code implemented:




However the resulting output is a bunch of bytecode, not html. An example output is:


Can someone please tell me what else I must do for the html to display correctly. I have set the Content type to text/html charset=UTF-8. I must also add that I am basing this code from an example that I have seen. The main goal was to read in from a tmp file the html content and display it to the user.

Thanks in advance.

[ November 26, 2007: Message edited by: Ulf Dittmer ]
John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
Any guidance with this is appreciated...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
It would seem that the file you are streaming to the browser does not in fact contain HTML, but a GIF image (as witnessed by its first few bytes).

(Pedantic correction: what that is is not bytecode -which is what Java classes consist of- but bytes.)


Ping & DNS - my free Android networking tools app
John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
Thanks Ulf for the reply...

Until now I was unable to recognize that as a .gif image. The file that is being read in does actually contain html. What are the requirments for reading in .gif images and writing them to an outputStream.

A better question may be, where may I find information on writing .gif images to a servlet outputStream? (from an html file...)

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
The method for streaming a GIF is the same as for HTML -in other words your code should work fine- except that the content type needs to be "image/gif" instead of "text/html".

I'm confused by your saying that the file actually contains HTML -when it really contains a GIF-, and what you mean by "writing .gif images ... from an html file", though. A file contains either HTML or a GIF, not both. Which is the case here?
John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
Ok, the actual file being read in has a .html extension. It is a report the has been exported as an html file. The report contains images within it (.gif's).
John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
A file contains either HTML or a GIF, not both


Would I have to read in each image as a separate file then?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
Yes. An HTTP response can only contain a single image anyway, so I'm not sure what you have in mind with reading several images. Can you elaborate on that?
John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
Thanks for the reply,

If you will notice, I have previously posted that my code is based off an example. I had left an important argument out of my code that is now being used. I am able to get all of the text from the file, but my image links are broken. I will keep investigating to find out how to resolve each image's src. Thanks you once again!
[ November 26, 2007: Message edited by: John Simpson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: write html from byte[] to response.getOutputStream