2

I need to retrieve rows in database with a image saved in byte array. How do I display the image using Strut2?

I have displayed it by using custom result. I passed the id and make an action search for it in the database. My problem is how to invoke this several times? I have an action that retrieve all the rows. How to call display image action from the list action? Or is there a better way to achieve this?

JAVA

My action has an list of the objects I want to show on JSP.

JSP

First way: I use iterator tag and on each iteration I want to display the image which is in byte array. I want call the action to retrieve the image here.

Second way: I tried this post and it is not working for me.

<img src="data:image/jpg;base64, <s:property value="imageData"></s:property> />" >

Image data is the image in string.

Community
  • 1
  • 1

1 Answers1

1

To retrieve rows in database there's many ways but all of them utilize JDBC API. You can map the object as an image array containing bytes or blob or clob data that you persist in the database.

Displaying the images required to send it to the browser. In the Struts2 there's a stream result type that could be used to output the image data to the browser.

Or use the Servlet API to transmit the data on the JSP similar like in How to send and display image from action class to JSP in Struts 2 answer.

Combining the experience from the answers that you already enlighten in the question to stringify data you may achieve suitable results.

Roman C
  • 49,761
  • 33
  • 66
  • 176