p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   JSP Basics (http://p2p.wrox.com/forumdisplay.php?f=92)
-   -   How to display pictures on JSP page? (http://p2p.wrox.com/showthread.php?t=16897)

coitri August 15th, 2004 11:00 PM

How to display pictures on JSP page?
Hi all, please give me your solution, thanks.
I have many pictures, stored in Oracle database (BLOB),

How to display them (pictures) on JSP page?

Thanks advance.

gokul_blr August 23rd, 2004 06:13 AM

This could be helpful for you, (support from Oracle)

Working with LOBs and BFILEs
This chapter describes how you use JDBC and the oracle.sql.* classes to access and manipulate LOB and BFILE locators and data, covering the following topics:

Oracle Extensions for LOBs and BFILEs
Working with BLOBs and CLOBs
Working with BFILEs


coitri August 30th, 2004 09:42 AM

Thanks gokul_blr,
But it's not helpful for me! [|)]

I have a database, and there are many picture, stored in BLOB field.
I want to query and display them on the JSP page,
Any more idea to me?

gokul_blr September 1st, 2004 01:30 AM

Look at the suggestion :
   dirname varchar2(255);
   v_filename varchar2(255);
   tool_env.getvar('DEMO60', dirname);
   dirname := dirname || '\bin\bmp';

   v_filename := get_file_name(dirname,NULL,
   'All Files (*.*)|*.*|' ||
   'JPEG Files (*.jpg)|*.jpg|' ||
   'Bitmap Files (*.bmp)|*.bmp|' ||
   'TIFF Files (*.tif)|*.tif|' ||
   'CompuServe Files (*.gif)|*.gif|' ||
   'PC Paintbrush Files (*.pcx)|*.pcx|' );

   if v_filename is not null then
      read_image_file(v_filename,'ANY','img_tab.img_tst' );
   end if;

Forms 6i doesn't support BLOBs, change type to "long raw" and it should work
or you can create a similar procedure and load the images using SQL*Plus.

gokul_blr September 1st, 2004 01:31 AM

Check, What Tom says :


coitri September 2nd, 2004 11:34 PM

yeah, thanks!
But I want to display stored images on the JSP page.

angrycat September 12th, 2004 04:33 PM

Got mySql solution from SunJava, would suggest you have a look there if your still stuck.

Assuming you are able to return the image into a recordset with something like:

String query = "select image from images where id =1";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);

The code youre really after goes something like this:

byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
while((size=sImage.read(bytearray))!= -1 )
        response.getOutputStream().write(bytearray,0,size) ;


The problem with this is that you cannot put it into a table etc. The original poster of the solution in the Sun forum 'included' the jsp containing the above in the table of a second jsp, which is what I do also.

Pallav September 21st, 2004 06:17 AM

Hi angrycat,
ur solution enables me to display an image (stored as blob data type in mysql) on a jsp page..

However i cannot display the image(a gif image) in a table..

I followed ur instruction and included ur code(say Your_Code.jsp)in a second jsp page but only the image got displayed,not the table and its contents..

the sample code of second jsp page(say show.jsp) is as follows

   <td><%@include file="Your_Code.jsp"%></td>
   <td><jsp:include page="Your_Code.jsp" flush="true"/></td>


the output of show.jsp is the gif image only without any html...

Kindly let me know how u implemented this functionality..


angrycat September 21st, 2004 07:53 AM


I did not use includes, I simply used the page as the image source:

<td><img src="getImage.jsp"></td>

What I havent tested is passing different parameters to the jsp page from this link, thus retrieving multiple records from the database, but Im pretty sure it will work.

bush September 21st, 2004 07:55 PM

in my opion, it is a mistake even if you did it succssfully.

 the computer will make it as a static page and it won't interprete

it again.

All times are GMT -4. The time now is 02:20 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.