Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need to display multiple images from database on a webpage

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Need to display multiple images from database on a webpage

    hi,

    I am able to display a single image from the database on a webpage using the

    following code:

    rs1 = st1.executeQuery("select image from pictures where id='5'");
          if(rs1.next()){
            int len = imgLen.length();
            byte [] rb = new byte[len];
            InputStream readImg = rs1.getBinaryStream(1);
            int index=readImg.read(rb, 0, len);  
            System.out.println("index"+index);
            st1.close();
            response.reset();
            response.setContentType("image/jpg");
            response.getOutputStream().write(rb,0,len);
            response.getOutputStream().flush();

    Can any one help me to get the code to display more than one image on a *.jsp file. I tried putting the while loop, but it is'nt doing the job.

    Thanks.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Need to display multiple images from database on a webpage.

    Hello raghuprasad,

    I think you should be able to change the query to get the results you need.

    Try this:

    rs1 = st1.executeQuery("select image from pictures where id in(5,6,7)");
          if(rs1.next()){
            int len = imgLen.length();
            byte [] rb = new byte[len];
            InputStream readImg = rs1.getBinaryStream(1);
            int index=readImg.read(rb, 0, len);  
            System.out.println("index"+index);
            st1.close();
            response.reset();
            response.setContentType("image/jpg");
            response.getOutputStream().write(rb,0,len);
            response.getOutputStream().flush();
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up issue solved

    Thanks friend,

    I got the solution. We need to call the servlet displaying image in the "src" attribute of

    <img> html tag.

    eg: <img src="/ImageServlet?imageno=1">

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Need to display multiple images from database on a webpage.

    Glad you solved your problem I will mark this thread as solved.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. traversing multiple jTabbedPane?
    By dewboy3d in forum AWT / Java Swing
    Replies: 3
    Last Post: October 2nd, 2009, 07:26 PM
  2. Which interface gives more control on serialization of an object?
    By abhishekraok2003 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 16th, 2009, 10:17 AM
  3. Updation of webpage to the last modified date
    By Revathy G in forum Java Programming Tutorials
    Replies: 1
    Last Post: May 6th, 2009, 04:47 AM
  4. How to display the contents of my queue?
    By rocafella5007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 30th, 2009, 11:46 AM
  5. What are the best way of placing images in GUI?
    By Ciwan in forum AWT / Java Swing
    Replies: 5
    Last Post: February 26th, 2009, 04:19 PM