RE: What is the best way to display pictures from a database usin g Struts

2002-01-09 Thread Jesse Alexander (KABS 11)

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 
> -
>  paramId="id" paramName="imageBean" paramProperty="id">
> -
> this hopefully renders to 
>   
> 
> 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
>   
> 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:   
For additional commands, e-mail: 

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: What is the best way to display pictures from a database usin g Struts

2002-01-09 Thread antony

It surely does help,  I shall put it to work now!

Cheers

Tony

Jesse Alexander (KABS 11) wrote:

> 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
> 



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: What is the best way to display pictures from a database usin g Struts

2002-01-09 Thread Olivier Dinocourt

There's one important thing to do, too : don't forget to set the mime-type,
else it will be text/plain or text/html, and your browser will display your
byte stream as text
- Original Message -
From: <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, January 09, 2002 6:40 PM
Subject: Re: What is the best way to display pictures from a database usin g
Struts


> It surely does help,  I shall put it to work now!
>
> Cheers
>
> Tony
>
> Jesse Alexander (KABS 11) wrote:
>
> > 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
> >
>
>
>
> --
> 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]>




Re: What is the best way to display pictures from a database usin g Struts

2002-01-09 Thread Jin Bal

A nice design for an action such as this is to create a "BinaryRenderAction"
which receives as request parameters the db reference of the image so it or
soime business delegate/DAO can retrieve it, and a reference to the
mime-type so that it can set the header in the response.

This way the action doesn't care what type of binary data it is rendering,
all it does is get some binary data from the db using the reference
suppplied and, then set the header in the response to the one that recieved
as a parameter (or to the one that is stored on the row if you db schema is
set that way)

All it needs to do now is write the bytes to the ServletouputStream and
return null in the perform() method and "Bobs you Uncle" a re-usable
BinaryrenderAction that can be used any where on the site...

HTH
Jin
- Original Message -
From: "Olivier Dinocourt" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, January 09, 2002 9:15 AM
Subject: Re: What is the best way to display pictures from a database usin g
Struts


> There's one important thing to do, too : don't forget to set the
mime-type,
> else it will be text/plain or text/html, and your browser will display
your
> byte stream as text
> - Original Message -
> From: <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Wednesday, January 09, 2002 6:40 PM
> Subject: Re: What is the best way to display pictures from a database usin
g
> Struts
>
>
> > It surely does help,  I shall put it to work now!
> >
> > Cheers
> >
> > Tony
> >
> > Jesse Alexander (KABS 11) wrote:
> >
> > > 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
> > >
> >
> >
> >
> > --
> > 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]>
>
>

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




Re: What is the best way to display pictures from a database usin g Struts

2002-01-09 Thread Ted Husted

+1 

How about a nice little package that also documented the standard mime
types as static finals, grabbed the mimeType and content from request
attributes, as as Jin, says "Bob's your Uncle". 

Anyone else interested in contributing this to the Actions package
before I do it myself :)

-Ted.

Jin Bal wrote:
> 
> A nice design for an action such as this is to create a "BinaryRenderAction"
> which receives as request parameters the db reference of the image so it or
> soime business delegate/DAO can retrieve it, and a reference to the
> mime-type so that it can set the header in the response.
> 
> This way the action doesn't care what type of binary data it is rendering,
> all it does is get some binary data from the db using the reference
> suppplied and, then set the header in the response to the one that recieved
> as a parameter (or to the one that is stored on the row if you db schema is
> set that way)
> 
> All it needs to do now is write the bytes to the ServletouputStream and
> return null in the perform() method and "Bobs you Uncle" a re-usable
> BinaryrenderAction that can be used any where on the site...
> 
> HTH
> Jin
> - Original Message -
> From: "Olivier Dinocourt" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Wednesday, January 09, 2002 9:15 AM
> Subject: Re: What is the best way to display pictures from a database usin g
> Struts
> 
> > There's one important thing to do, too : don't forget to set the
> mime-type,
> > else it will be text/plain or text/html, and your browser will display
> your
> > byte stream as text....
> > ----- Original Message -
> > From: <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Wednesday, January 09, 2002 6:40 PM
> > Subject: Re: What is the best way to display pictures from a database usin
> g
> > Struts
> >
> >
> > > It surely does help,  I shall put it to work now!
> > >
> > > Cheers
> > >
> > > Tony
> > >
> > > Jesse Alexander (KABS 11) wrote:
> > >
> > > > 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

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