Hi,

A Diumenge 20 Octubre 2002 17:09, Frederic Laub va escriure:
> Hi,
>
> I'm also interested in the two cases.
> The first case is clear to me, writing the byte data directly to out.
> The second case, I would appreciate if you could clarify. What do you mean
> by holding the content type in the bean.
> An example of the second option would be wonderful!
>

I mean creating a value object, something like an implementation of 
        org.apache.struts.upload.FormFile

to hold the binary data, the content type ("image/png", "image/jpg" .... ), 
etc ...

Then, the Action would call the business methods to get this value object and 
would save it in the request, and forward to a servlet that would retrieve 
the value object from the request, set the content type and write the data to 
the response.

This way you can reuse the servlet in case you have documents, like pdfs in 
your database as blobs or something.

Every time you need to stream a file, you only need to define an action that 
calls the business method to get the file value object and save it to the 
request.

In struts-config.xml you would have something like this:

        <action path="/showImage" 
                type="the.action.that.gets.the.Image">
            <forward name="success" path="/fileServlet" />
        </action>

        <action path="/showDocument" 
                type="the.action.that.gets.the.Document" >
           <forward name="success" path="/fileServlet" />
        </action>

and in web.xml

  <servlet>
    <servlet-name>fileServlet</servlet-name>
    <servlet-class>the.servlet.that.writes.the.Files</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>fileServlet</servlet-name>
    <url-pattern>/fileServlet</url-pattern>
  </servlet-mapping>


Salut,

 --Antoni Reus

> Thanks in advance.
> Frederic
>
> -----Original Message-----
> From: Antoni Reus [mailto:antoni.reus@;wanadoo.es]
> Sent: 20 October 2002 16:12
> To: Struts Users Mailing List
> Subject: Re: about images and db
>
> A Diumenge 20 Octubre 2002 15:34, kiuma va escriure:
> > thx , for your reply but I meant if was possible something like
> >
> > <html>
> > ...
> > hello!<img src='....'/>
> > ..
> > </html>
> >
> > using only custom tags
>
> Then, the are 2 different requests, the one that returns the html and the
> one
> that returns the image (you can't include the image data in the html)
>
> In the html you could have:
>
> <html>
> ...
> hello!  <html:img page="/showImage.do" paramId ... paramName ..../>
> ...
> </html>
>
> And  showImage.do  would be the Action that we talked about before.
>
> > Antoni Reus wrote:
> > >Hi,
> > >
> > >A Diumenge 20 Octubre 2002 11:47, kiuma va escriure:
> > >>What could you suggest to me to display images stored in a database.
> > >>When I get them in a bean what could I do to show them on a web d.
> > >> page?
> > >
> > >You can:
> > >
> > >1. In a Action:
> > >   response.setContentType( "the type of the image" );
> > >   OutputStream out = response.getOutputStream();
> > >   ... write the data (byte array?) to out ....
> > >   return null;
> > >
> > >2. Or you could save the bean representing the image (content type, and
> > > data) in the request and forward to a servlet, and write the data to
> > > the response in the servlet.
> > >
> > >
> > >--
> > >To unsubscribe, e-mail:
> > > <mailto:struts-user-unsubscribe@;jakarta.apache.org> For additional
> > > commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>
> > >
> > >.


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to