• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write html from byte[] to response.getOutputStream

 
John Simpson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any guidance with this is appreciated...
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
John Simpson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic