Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent - display Image (binary) + html in single page

 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to present Image(binary) using HttpServletResponse.getOutputStream (), but I am not able to present <html> content with this image.
I would be thankful to you for your help & suggestions.

Thanks & Regards,
Sanjeev.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop - take a look at the source of any web page that has an image in it. What do you see? You see that the image data is not served with the HTML, instead there is an <img tag that has a src attribute which points to where the browser should obtain the image data. You can't create HTML plus image data in a single pass, the image has to come in a separate request.
If you want a servlet to serve binary image data, your HTML page must be generated with a <img src="URL that points to the servlet.
You are on the right track using an OutputStream - not a Writer.
Be sure to set the response content-type to match the image encoding. If possible you should also set the content-length.
Serving image and other binary resources comes up frequently, so do some searching.
Bill
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot I have done it same way. thanks for replying.

regards,
sanjeev.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic