• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

write html from byte[] to response.getOutputStream

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any guidance with this is appreciated...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic