struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "SUPRIYA MISRA" <supriya_mi...@hotmail.com>
Subject How do deal with JPEG in JSP's
Date Tue, 28 Aug 2001 13:30:55 GMT
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


Mime
View raw message