Hi,
I am storing jpeg images in oracle as BLOB. I am using the
connection.getBlob() method to retrieve the images. When I write this back
as a jpeg file it works great. How do I display the image in JSP's? Here is
the code I am using.
<%@ page import="java.sql.* ,java.util.*" %>
<%@ page errorPage="error.jsp"%>
<%@ page buffer="50kb"%>
<jsp:useBean id="connection" class="ITTPDB" />
<%
response.setContentType("image/jpeg");
String sql="select * from IMAGETEST";
ResultSet result=connection.executeQuery(sql);
char c;
byte [] b;
int i=0;
if (result.next()) {
Blob blob=result.getBlob("PHOTO");
b = blob.getBytes(1,(int)blob.length()+1);
//writing to file works
java.io.FileOutputStream fos = new java.io.FileOutputStream("c:\\test.jpg");
fos.write(b);
fos.close();
// Displaying in JSP does Not
while (i<blob.length()) {
c=(char)b[i++];
%>
<%=c%>
<%
i++;
}
}
%>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp