Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Displaying Image in JSP page

481348Sep 6 2006 — edited Aug 25 2008
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 22 2008
Added on Sep 6 2006
6 comments
912 views