• 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

How to send image with servlet using ServletStreams

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic