File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Display Images using Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display Images using Struts" Watch "Display Images using Struts" New topic
Author

Display Images using Struts

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
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.


Thanks,
Kumar
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
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
 
subject: Display Images using Struts
 
Similar Threads
how to display multiple images in jsp from database
how to retrieve and edit images in jsp
image upload
Displaying images on JSP page
executing code when a session expires?