• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send image with servlet using ServletStreams

 
Huzefa Zohaib
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to include an image in my HTML using servlet and servletStreams.
So please give me a simple code that how will I do this.
Thank You
 
Eric Blische
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya,
In my experience the appropriate approach is
to return the
<IMG SRC="http://eric:80/images/someimage.gif" HEIGHT="100" WIDTH="100" BORDER="1" />
element in the html your servlet is generating, and keeping the image(s) on a webserver where they can be "brought over" at the appropriate time (ie, when the html is loaded in a browser).
Hope this helps,
Eric
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a servlet serve any binary resource data such as an image. You have to set the response type correctly with setContentType, and in most cases you have to setContentLength for best results. This question has been asked many time in this forum, so do a search.
Any good servlets book will give an example.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!