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

http://download-west.oracle.com/docs...ob.htm#1000888



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 :
----------------------------------------
declare
   dirname varchar2(255);
   v_filename varchar2(255);
begin
   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;
end;
------------------------------------------------

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 :

http://asktom.oracle.com/pls/ask/f?p...D:239814548726


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);
rs.next();

The code youre really after goes something like this:


byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=getimage.jpeg");
while((size=sImage.read(bytearray))!= -1 )
    {
        response.getOutputStream().write(bytearray,0,size) ;
    }

        response.flushBuffer();
sImage.close();

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

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

</tr>
</table>

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

Kindly let me know how u implemented this functionality..

Thnx..

angrycat September 21st, 2004 07:53 AM

Sorry,

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.