Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Display Images using Struts

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In our application we have a requirement to store/retrieve images at maximum 15 on a single page. And we are using Struts as MVC and Spring as Delegate layer.

We are able to store the images in the Database successfully and also we are able to retrieve images in the BinaryStream format into java object. Now we got stick here before showing the images on JSP using Struts.

I can display the images using Servlet, but for each image I need to call Servlet. That I feel not a good way to display the images.

Is there any alternate way to display multiple images using Struts? or any other way also? could some one give me the small clue on this.

thanks in advance.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create a Struts Action that writes the image to the Response Object's OutputStream just as a Servlet would and have it return a null ActionForward. Then call this action from the Struts html:img tag. Example:

This code calls an action mapped as /ImageAction, passing the parameter imageId to the URL with the value of someBean.getSomeProperty() so that the URL passed would look something like this:

http://myserver.com/myapp/ImageAction?imageId=xyz
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you merill for your reply..

it helps me .. but I have couple of questions..

1)If my page required to display multiple images, then I need to call the action for multiple times? I think multiple times I need to call the database also, then it would be impact on N/W trafic.

2) I have bean which have the data from database to display on JSP, using this bean we can display easily if it is normal data. What if the same bean does contains byte array (stream for image){stored as image in the DB), is that possible to display the image if we have that data? this would be reduce the N/W trafic.

Could you please give me suggestion
 
Are you here to take over the surface world? Because this tiny ad will stop you!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic