File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display Images using Struts

 
Simpson Kumar
Ranch Hand
Posts: 261
  • 0
  • 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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • 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
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic