Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning an image from JSP  RSS feed

 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to return a 1x1 pixel "spacer.gif" image when a page named "image.jsp" is called. Can someone tell me how I could do that?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to display such an image? If so, simply use an <img> tag on the page referencing the image file.

Fi mean to retuyrn the image data as the response, that's not something you want to to with a JSP. JSP is designed to return cahracter not binary data, and the chance that your binary data will be corrupted is high. Read this article to find out why.

A servlet is much better suited to this purpose.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. spacer images are so 1998. What can a spacer image do for you that simple CSS cannot?
 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, Bear.

I will use a servlet then.

This script will mainly be called by a remote site... it doesn't need to be a spacer.gif... any image will do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!