I am very new to STRUTS, I am using example code for reference. My question is what is the next step I should do after I got the image back from DB as byte array from MyAction class and haveign the JSP reference back to that image? I can't reference back to the MyAction class because it is gone. Please help..
It sounds like you're referring to one of jsps in the struts-examples.war that comes with the download.
There is an example of how to load an image from a binary stream, such as you might get by retrieving a BLOB from a database.
In the exercise subdirectory, there is a html-img.jsp which has the following tag:
<html:img action="/html-img-action" />
In the struts-config.xml file, the action html-img-action is mapped to the class ImageAction. The execute() method for this class returns null, which means that it's not forwarding to a jsp, but rather creating the output directly. The class gets the printWriter from the response object and writes the byte stream of the image directly to it.
In answer to your question, by using the action attribute of the html:img tag, you are having the action write the byte stream into an image. All you have to do is provide an action class that will write a byte stream that will translate to an image. [ March 16, 2005: Message edited by: Merrill Higginson ]
Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy which we try to strictly enforce. Please re-read this document and edit your display name in order to comply. Thanks in advance, and we look forward to seeing you around the Ranch.
Joined: Jan 24, 2005
Thank you Merrill.
I found the codes in the example. However, I am using WSAD v5.1.1 which will only support Struts v1.1 and "action" attribute is not included in <html:img> tag in Struts v1.1.
I am still trying to find out how to use newer verion of Struts in WSAD v5.1.1. Is there any other way in Struts v1.1 that I can reference the generated image in the any Action class from my JSP?
Thank you very much for your help, Peter
Joined: Feb 15, 2005
You could code an <img> tag with regular html. Then specify "myAction.do" as the src attribute.
Also, you could try replacing the jar files in your project with the Struts 1.2 jars. The WSAD tooling might get a little confused, but it should run OK.