• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display image in JSP from BLOB captured in Oracle  RSS feed

 
A Chauhan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am working on a web application. I have captured an image as blob in oracle database. Can anyone have an idea how to display the same image in JSP. I have tried with following code but it doesn’t show any image only X is coming in place of image.

byte[] imgData = null ;

int size=0;
sImage = rs.getBinaryStream("STRUCTURE");
response.reset();
response.setContentType("image/jpeg");

response.getOutputStream().write(bytearray,0,size);

imgData = queryStructure.getBytes(1,(int)queryStructure.length());
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();

Thanks in advance
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP serves nothing else than plain HTML/CSS/JS.
Images in HTML are to be displayed using <img> tag.
The <img> tag has a 'src' attribute which should point to a valid URL of the image.
The URL of the image could point to a Servlet which writes the image to the outputstream.

If the image does not show up, then the URL is simply invalid or the binary stream is simply corrupt.

That said, your code is quite memory hogging. Use a byte buffer, otherwise the server will crash with OutOfMemoryError when a lot of (big) images are requested concurrently. You can find here an example of a decent ImageServlet: http://balusc.blogspot.com/2007/04/imageservlet.html
 
A Chauhan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip but i have to convert Blob in image . Can you provide any idea regarding this.
How can i give url for the same .

Thanks in advance
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already have given a link with an example (note that the article contains two examples, as stated in the introductory text).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!