Results 1 to 4 of 4
  1. #1
    g.raaja is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default In struts1.3 how to display multiple images in jsp from database

    Hi,

    I am facing problem in displaying multiple images at a time in jsp. I am able to retrieve the images from db and storing them in a list and forwarding that to jsp in request from Action class. But I am not able to display those images in jsp. I am not getting an idea how to render those images which are in the List collection. I am using struts 1.3.

    If any one have idea please guide me.

    Thanking you

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: In struts1.3 how to display multiple images in jsp from database

    How are you doing this?
    What does your List of images contain?
    Some code might help as well.
    What does your <img> tag look like?
    Please do not ask for code as refusal often offends.

  3. #3
    g.raaja is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default Re: In struts1.3 how to display multiple images in jsp from database

    Hi,

    My list of images contains the details of the images from db like imageid, name, imagedescription, category, image. Which I am storing in the form of bean objects and storing them in List. While iterating I want to read the image in the form of byte[] from the bean and display it without hitting the db again. I am not able to pass this bean to image tag.

    I tried like this

    Java Code:
    <logic:notEmpty name="flowerList">
    	<logic:iterate id="flowers" name="flowerList" >
    	<html:img src="../getFlowers.do" paramName="flowers" paramProperty="flowerImage"/>
    </logic:iterate>
    In the action class

    Java Code:
    List<FlowerBean> flowers = flowerdao.getFlower(categoryid);
    for(FlowerBean f:flowers){
            response.setContentType("image/jpg");
    	response.getOutputStream().write(f.getFlowerImageUrl(),0,f.getFlowerImageUrl().length);
    }
    But this will hit the db again and at the same time it will always print only one image.

    another form I tried in the JSP is
    Java Code:
    <%
    
    List<FlowerBean> fb=(List<FlowerBean>)request.getAttribute("flowerList"); 
            for(FlowerBean fbs:fb){
    		response.setContentType("image/jpg");
    		response.getOutputStream().write(fbs.getFlowerImageUrl(),0,fbs.getFlowerImageUrl().length);
    	}
    %>
    But this is giving an exception outputstream already opened and not printing any thing.

    I dont want to hit the db for more than once. If in the first method above if I can send the bean through image tag and catch that in action class I think I can able to print. But I am struck in sending the bean object and catching that in Action.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: In struts1.3 how to display multiple images in jsp from database

    You can't do it like that.
    If you have an html page on the client browser, then the <img> tags will result int he server being asked for the images.
    That's simply how it works.

    You cannot supply byte[] in the HTML page and hope they display an image.

    You can display a single image on the page, if it's contentType is marked as an image, in which case it is not html.

    You have to have that trip to the server for the image.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 3
    Last Post: 12-05-2011, 01:28 PM
  2. How to display Images?
    By Rectal Exambot in forum New To Java
    Replies: 12
    Last Post: 10-11-2010, 04:36 AM
  3. Replies: 2
    Last Post: 04-01-2010, 04:35 AM
  4. display images
    By prof.deedee in forum AWT / Swing
    Replies: 10
    Last Post: 11-12-2009, 09:08 PM
  5. Dynamic display of images
    By gixerino in forum NetBeans
    Replies: 7
    Last Post: 01-15-2009, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •