Displaying Image in JSP page
481348Sep 6 2006 — edited Aug 25 2008Hi there.. I have a problem with displaying an image from table with blob data type.
Here's what have I done:
I have this page to display an image from requestScope.test (I've set this value in data action).
But the problem is, the image is only displayed once. Seems that after it read the eof of stream, It'll not move the pointer to the beginning. The image will show up again if view object retrieve new data from the database.
Here's my code:
------------------------------------------------------begin of code----------------------------------------------------
<%@ page import="java.io.InputStream,oracle.jbo.client.Configuration,oracle.jbo.ApplicationModule"%>
<%
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=img.jpg");
InputStream sImage = ((oracle.jbo.domain.BlobDomain)request.getAttribute("test")).getInputStream();
byte[] bytearray = new byte[4096];
int size = 0;
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
sImage.close();
%>
------------------------------------------------------end of code----------------------------------------------------
Any suggestion?
Thx,
Andre