You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gary Feidt <Ga...@childrensmn.org> on 2006/01/24 15:53:04 UTC

Displaying Images from database using Struts tags

Hi Everybody,

I'm using Struts 1.2.4, with no frills (JSTL, Struts EL) - just using
Struts framework and tags.

I am exploring the ability to display images from database - never done
this before.  I'm guessing I can get the data out by using the
java.sql.getBinaryStream

Will the <html:img> tag display a java.io.InputStream, or is there a
better way?

Thanks,

Gary
__________________________________

Confidentiality Statement:
This email/fax, including attachments, may include confidential and/or proprietary information and may be used only by the person or entity to which it is addressed. If the reader of this email/fax is not the intended recipient or his or her agent, the reader is hereby notified that any dissemination, distribution or copying of this email/fax is prohibited. If you have received this email/fax in error, please notify the sender by replying to this message and deleting this email or destroying this facsimile immediately.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Displaying Images from database using Struts tags

Posted by Niall Pemberton <ni...@gmail.com>.
I think you're thinking about this the wrong way round. Tags run on
the server to generate HTML content - so all the <html:img> tag does
is render the html markup of <img src="...."> - its then the browsers
job to download the image referenced in the "src" attribute.

So what you need is to specify a url in that src attribute which will
run something on the server to get your image from the database and
return the image's content as the response. You can do that with a
Struts action - retrieve the image, write it out as the response and
return "null" (rather than an action forward) - setting the
appropriate content stuff.

There is a "download action" which is designed to make this kind of
thing easier (Ithink it was introduced in Struts 1.2.4), details here:

http://wiki.apache.org/struts/StrutsFileDownload

Niall

On 1/24/06, Gary Feidt <Ga...@childrensmn.org> wrote:
> Hi Everybody,
>
> I'm using Struts 1.2.4, with no frills (JSTL, Struts EL) - just using
> Struts framework and tags.
>
> I am exploring the ability to display images from database - never done
> this before.  I'm guessing I can get the data out by using the
> java.sql.getBinaryStream
>
> Will the <html:img> tag display a java.io.InputStream, or is there a
> better way?
>
> Thanks,
>
> Gary

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Displaying Images from database using Struts tags

Posted by Hubert Rabago <hr...@gmail.com>.
You'd have to write an Action which reads the image from the DB and
writes it onto the servlet's output stream.  There was a thread just
yesterday which discussed how to do this.  You can set your image URL
to that action and provide it with enough parameters to find your
image in the DB.

Hubert

On 1/24/06, Gary Feidt <Ga...@childrensmn.org> wrote:
> Hi Everybody,
>
> I'm using Struts 1.2.4, with no frills (JSTL, Struts EL) - just using
> Struts framework and tags.
>
> I am exploring the ability to display images from database - never done
> this before.  I'm guessing I can get the data out by using the
> java.sql.getBinaryStream
>
> Will the <html:img> tag display a java.io.InputStream, or is there a
> better way?
>
> Thanks,
>
> Gary
> __________________________________
>
> Confidentiality Statement:
> This email/fax, including attachments, may include confidential and/or proprietary information and may be used only by the person or entity to which it is addressed. If the reader of this email/fax is not the intended recipient or his or her agent, the reader is hereby notified that any dissemination, distribution or copying of this email/fax is prohibited. If you have received this email/fax in error, please notify the sender by replying to this message and deleting this email or destroying this facsimile immediately.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Displaying Images from database using Struts tags

Posted by Dave Newton <ne...@pingsite.com>.
Gary Feidt wrote:
> Will the <html:img> tag display a java.io.InputStream, or is there a
> better way?
>   
Not that I know of, unless the tag API doc at
http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-html.html#img
is wrong.

You can, however, use an action or a servlet to deliver the image data.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org