Possible Duplicate:
How to retrieve and display images from a database in a JSP page?
I want to display an image in a <td>
tag of a table. The code is working fine but I am not able to retrieve the image in the <td>
tag of the table
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*,java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:IMG");
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs=st.executeQuery("select image from img");
%>
<table width="100%" border="2">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
while(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
InputStream sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
%>
<tr>
<td> </td>
<td><img src="<%= response.getOutputStream().write(bytearray,0,size)%>"width=50 height=50 /></td>
<td> </td>
</tr>
<%
}
}
%>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>