Perhaps the result name in my example does not correspond to the return value of your action ?
I assume you are using the param interceptor here

public class ImageAction {
   private    int imageId;
   private    Image image;
// this method is called when using the param-interceptor
   public void setImageId(int imageId) {
      this.imageId = imageId;
   }

   public InputStream getImageStream() {
      // create a stream from your image
   }

   public String execute() {
      // get image
image = dao.getImage() // or something like that, could be in the prepare method if you're using the prepare interceptor

return "all"; // if you use "success" here, you have to modify the result name in your struts.xml
   }
}

hope this helps

bartlebooth



Roberto Nunnari wrote:
Hi bartlebooth.

That is very neat!

But the getImageStream method in my action is never called..

why?



bartlebooth wrote:
You could use the stream result-type.

           <result name="all" type="stream">
               <param name="contentType">image/jpg</param>
               <param name="inputName">imageStream</param>
<param name="contentDisposition">filename="image.jpg"</param>
               <param name="bufferSize">1024</param>
           </result>

In your action, you have to provide a method getImageStream (corresponding to the inputName parameter above).

public InputStream getImageStream() {
   // create a stream from your image
}


Josh Vickery wrote:
If you return null from your Action you can write directly to the response:

HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("image/jpg");
out = response.getOutputStream();
write image here
return null;

On 7/18/07, Roberto Nunnari <[EMAIL PROTECTED]> wrote:
hehe.. ok.. let's add some context..

Till now I was using a servlet to serve to the web images stored
in a database. To access the database I had the myDAO
object in the applicationContext and so it was accessible by
the servlet and actions.

Now I have added Spring to the game, and the myDAO object is
no longer in the applicationContext, as it is managed by Spring.

All my actions now extends a base class that has a setMyDAO
method, and so they get access to the myDAO object.

But what about the servlet? It will not be injected by Spring.

What is the solution?

Thank you.

Best regards.

--
Robi.



Roberto Nunnari wrote:
> Hello.
>
> What is the best way to serve images stored in database in Struts2?
>
> action, resultType, or servlet?
>
> Thank you.
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to