Web Design and Development Forums

Problem with my Servlet - retrieving images from database

This is a discussion on "Problem with my Servlet - retrieving images from database" within the Java, JSP, Cold Fusion section. This forum, and the thread "Problem with my Servlet - retrieving images from database are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > Java, JSP, Cold Fusion

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Dec 18th, 2007, 16:27   #1 (permalink)
Junior Member
 
Join Date: Feb 2007
Location: USA
Posts: 45
Question Problem with my Servlet - retrieving images from database

I have a servlet that retrieves an image from a mysql database, then the image is displayed within the JSP that calls the servlet. The images themselves are uploaded into the database via another servlet. They are stored as type Blob and retrieved as the same type. Then they are read into a Byte[] array.

A snippet of my servlet code that retrieves the image from the db:
Code: Select all
//…
  bufout = new BufferedOutputStream(res.getOutputStream());
  int int_blob_length = (int)blob_length; 
  byte by[] = new byte[int_blob_length];
  int index = 0;
              while ( index != -1 ) {                          
                          index = in.read( by, 0, int_blob_length);
                          
                          //bufout.write( by, 0, int_blob_length);                                                                      
                          
                          //this if clause is a newer update to my code, because I was getting
                          //ArrayIndexOutOfBoundsException’s, and this clause fixed that issue
                          if(index = = -1) {
                             bufout.write( by, 0, 0);
                          } else {
                             bufout.write(by,0,index);
                          }//if                              
              }//while
                          
                          bufout.flush();
                          bufout.close(); 
   
  //…

Within the JSP page there are 5 calls to the servlet via statements below :
Code: Select all
<img src = "anything.viewimage?acc=4750&num=image1">
  <img src = "anything.viewimage?acc=4750&num=image2">
  <img src = "anything.viewimage?acc=4750&num=image3">
  <img src = "anything.viewimage?acc=4750&num=image4">
  <img src = "anything.viewimage?acc=4750&num=image5">
The problem I’m experiencing is that more often than not, one of the 5 images are not being displayed . Instead of the image I’m getting a red X. My JSP page is setup with javascript code as well, which involves these 5 images. There is one large image, and 4 thumbnails beneath it. The user clicks on a thumbnail to enlarge it, thus changing the main image above to the full size of the thumbnail.

I think what’s happening is that the index variable is –1 at some point and the image isn’t coming through the buffer…but why would it go to –1? Can someone please help me decipher the problem? I want to have a smooth running servlet for retrieving images from the database…your input is appreciated.



Thank You

Love2Java
Love2Java is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 19th, 2007, 13:20   #2 (permalink)
Junior Member
 
Join Date: Feb 2007
Location: USA
Posts: 45
Re: Problem with my Servlet - retrieving images from database

bump...hope that this is allowed on this forum, if not, I apologize...but I really need help with my coding problem.
Love2Java is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with insert into the database kool77 PHP Forum 3 Jun 4th, 2007 19:21
upload images in database and folder manzil PHP Forum 1 Aug 11th, 2006 16:06
problem in Servlet Deployment on remote site theoryyes Java, JSP, Cold Fusion 7 Sep 17th, 2005 11:17
Retrieving text from database and writing back as url wheatus ASP Forum 5 Dec 22nd, 2004 11:36



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:00.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59