Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 15th, 2004, 11:00 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coitri Send a message via MSN to coitri Send a message via Yahoo to coitri
Default 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.


  #2 (permalink)  
Old August 23rd, 2004, 06:13 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

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


  #3 (permalink)  
Old August 30th, 2004, 09:42 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coitri Send a message via MSN to coitri Send a message via Yahoo to coitri
Default

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?

  #4 (permalink)  
Old September 1st, 2004, 01:30 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

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.




  #5 (permalink)  
Old September 1st, 2004, 01:31 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

Check, What Tom says :

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

  #6 (permalink)  
Old September 2nd, 2004, 11:34 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coitri Send a message via MSN to coitri Send a message via Yahoo to coitri
Default

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

  #7 (permalink)  
Old September 12th, 2004, 04:33 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

  #8 (permalink)  
Old September 21st, 2004, 06:17 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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..
  #9 (permalink)  
Old September 21st, 2004, 07:53 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

  #10 (permalink)  
Old September 21st, 2004, 07:55 PM
Registered User
 
Join Date: Sep 2004
Location: ningbo, , China.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display pictures on JSP page? Kisat JSP Basics 1 November 3rd, 2008 09:02 PM
JSP page not display data coming from socket ashvinm JSP Basics 0 February 20th, 2008 02:10 AM
Display many pictures NBM Java GUI 0 September 3rd, 2006 06:54 AM
How to display Vietnamese Unicode on JSP page? minhpx JSP Basics 4 May 18th, 2006 11:16 PM





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