This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSP and the fly likes Display of images in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Display of images in JSP" Watch "Display of images in JSP" New topic

Display of images in JSP

Shrikant Kulkarni
Ranch Hand

Joined: May 10, 2005
Posts: 42
I am new to handling of BLOB objects.
i want to display all the images present in a particular table for a particular ID: The sql query is as below
select image from image_upload where log_id=?
Note: image is BLOB type

In jsp:
I get a ResultSet (rs):

InputStream inputStr = rs.getBinaryStream(1);
byte[] bytearray = new byte[4096];
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int nbytes = 0; // Number of bytes read
while( (nbytes = != -1 )
outStream.write(bytearray, 0, nbytes);
outStream .close();
<td valign = "baseline">
<img align = "bottom" src = "<%=imageName%>" alt="<%=imageName%>" height="100" width="100"/>

But in JSP page it displayed a broken image link, not the image which i got it from database.

Can any one please tell me what piece of code i should write in order to display all the images??
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
You are a little confused on how images are processed in a displayed page in a browser. Each image is seperately loaded by the browser using a new request to the server. Therefore, you need to have a send server process to handle the image. I would suggest a servlet for that.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Display of images in JSP
jQuery in Action, 3rd edition