permaculture playing cards*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Display of images in JSP" Watch "Display of images in JSP" New topic
Author

Display of images in JSP

Shrikant Kulkarni
Ranch Hand

Joined: May 10, 2005
Posts: 42
Hi,
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):

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

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
Sheriff

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: http://aspose.com/file-tools
 
subject: Display of images in JSP
 
Similar Threads
uploading multi images by using file upload...
How to retrieve image from ms access database through jsp
How to display an image that is stored in a table in Mysql , on a JSP page
Download file HELP?
Retrive image from MySQL database in fix format on JSP page