• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing Image on Stream  RSS feed

 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to write image on response stream in JSP Custom tag, can i do that? I've tried at Servlets and its working fine, but in JSP Custom tag in doStartTag() or doEndTag() i have JSPWriter object, using that how can i write image? any idea?

Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP are designed to write character streams, not binary data like images. Thats why you get a JSPWriter - its for characters.

You can NOT mix characters and binary data in a single response - JSP should write an <IMG tag with a URL that points to your servlet.

Bill
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please provide some sample code to do that? It will be really helpful.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you already did most of the work. If you already have a servlet that streams the image data, that's 99% of the code.

Now all you need to do is to create an <img> tag in the JSP whose src attribute addresses the servlet. You don't need sample code for that, do you?
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you do need sample code to clarify:



It sounds like you've already got code for 'ImageServlet'
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply

But for Servlet, i had created the image bytes in servlet and put them on the output stream of response thats all good.

But now in JSP Custom Tag, i have bytes in the custom tags how should i give them to servlet through <img> tag?

I think i can store them in session and in servlet retrieve it from session and create the image but i need to show 3 or 4 this kind of images of graph on the page and it will be lot of data to store in session.

Any other idea?

Thanks again
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ali Gohar:
TBut now in JSP Custom Tag, i have bytes in the custom tags how should i give them to servlet through <img> tag?


You don't. The image bytes are completely useless to your JSP. You don't need them there.

No session, no storing, no image bytes.

Just use the <img> tag to reference the servlet from the JSP. The servlet should handle everything reagrding serving the image bytes.

Why are you making this complicated?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!