Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP 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
 
Old April 22nd, 2006, 04:34 PM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default strange problem with displaying LOB images in JSP

hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using the servlet.

Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5

here is one of my image servlet's working versions (the essential part) :

Code:
               BLOB blob=null;
        rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");

        while (rset.next()) 
            blob=((OracleResultSet)rset).getBLOB(2);

        response.reset();
        response.setContentType("image/jpeg");
        response.addHeader("Content-Disposition","filename=42.jpeg");

                ServletOutputStream ostr=response.getOutputStream();

               InputStream istr=blob.getBinaryStream(1L);

                int size=blob.getBufferSize();
        int len=-1; 

                byte[] buff = new byte[size];

                    while ((len=istr.read( buff ))!=-1 ) {
            ostr.write(buff,0,len); 
            }

        response.flushBuffer();
        ostr.close();
and my JSP page code :

Code:
 
<img src="/ImageServlet" border="0"  >
If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

 
Old April 23rd, 2006, 03:48 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.

here's the magic tag :
Code:
 <img src="ImageJSP.jsp" border="0"  >
enjoy : )






Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying images chandan121 JSP Basics 0 May 1st, 2008 09:59 PM
Displaying images...... kethireddy435 ASP.NET 2.0 Professional 0 September 16th, 2007 09:25 PM
displaying images in jsp using struts vijayalexander JSP Basics 0 November 6th, 2006 09:46 AM
strange problem while displaying child form in mdi avats General .NET 1 June 20th, 2005 08:06 PM
Displaying images inbox Classic ASP XML 2 May 4th, 2005 03:08 AM





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