This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display of images in JSP

 
Shrikant Kulkarni
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic