Hi,

from an Action's perform() you can do two things:
a) do something (usefull) and return an ActionForward-object
b) do somthing (usefull), write the desired output (html, pdf-stream,
   image-bytes,...) to the response-objects output (just like standard
   servlet-programming!) and return a NULL-object (return null)
in this case you want to use b). Important is returning null to indicate 
that the Action did complete the processing. Else ActionServlet will pass
on to the returned ActionForward-object...

hope this helps
Alexander Jesse

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 09, 2002 5:20 PM
To: Struts Users Mailing List
Subject: Re: What is the best way to display pictures from a database
using Struts


Hi


When you say that I should use an action and "write the bytes in the 
perform method" I am not quite sure I follow.  I have only returned an 
ActionForward object from the perform() method in an Action class.  So 
how do I make it return a byte string representing the image?, should I 
write another perform() method?

Cheers

Antony


> in the JSP you write an image tag like 
> ---------------------------------------------------------
> <img src="<html:rewrite page="/servlet/ImageServlet" 
> paramId="id" paramName="imageBean" paramProperty="id">
> ---------------------------------------------------------
> this hopefully renders to 
>       <img src="/servlet/ImageServlet?id=1234432">
> 
> This will cause an extra http request to the mapped servlet. 
> 
> In the servlet you should do something like:
> ---------------------------------------------------------
> response.setContentType("image/gif");
> response.setContentLength(imageBean.getLength());
> response.setHeader("Content-disposition","attachement;
> filename="+imageBean.getFilename());
> ServletOutputStream stream = response.getOutputStream();
> //copy dbstream to servletOutputStream
> stream.write(imageBytes);
> ---------------------------------------------------------
> Instead of the servlet you could probably use an action
>       <img src="/ImageAction.do?id=1234432">
> and write the bytes in the perform method, but I did not test this one.

>>
>>>Hi
>>>
>>>I need to retrieve pictures from a database and use struts to display
>>>them.   I am not sure about the best way to do this.  Can someone please
>>>tell me how they do it and what they beleive the best approach is.
>>>




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

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

Reply via email to