Question

I am currently working with Stripes and I have an ActionBean that loads a specific User object JavaBean (Email, First Name, Last Name, Blob image) from my database according to a parameter in the url. This ActionBean then forward to a JSP page that displays these information by using the ActionBean and accessing the User object instance (property of the ActionBean).

I have no problems displaying the text data (Email, First Name and Last Name) but I don't really know how I can display the Blob image (it's a byte array) dynamically.

Is there a way, maybe using a tag from the Stripes Tag lib to load a event (Resolution) that would load the image from the current ActionBean and display it when the page is loaded?

I thought I could call an Resolution (event) from the User JavaBean as the src of the tag but he doesn't seem to work...

public Resolution loadPicture(){
    StreamingResolution sr = null;

       return sr = new StreamingResolution("image/jpeg") {
             public void stream(HttpServletResponse resp) throws Exception {
                 OutputStream os = resp.getOutputStream();
                 os.write(this.user.getBlob());
                 os.close();
             }
         };
}

Thanks in advance!

Was it helpful?

Solution

That's not how HTTP and HTML works. A request is used to load the HTML code. This HTML code contains various <img src="..." /> tags, and a new request is made to load each image. You must generate HTML with img tags that have their src point to a Stripes action which will load the image and stream it to the response.

A StreamingResolution is the right approach to implement this action, but the action will have to be called from another request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top