You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by an...@claire.co.jp on 2001/11/22 08:18:40 UTC
What is the best way to display pictures from a database using Struts
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.
Cheers
Antony
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: What is the best way to display pictures from a database using
Struts
Posted by Ted Husted <hu...@apache.org>.
See the source code for org.apache.struts.actions.ReloadAction
It writes "OK" when it's done. Makes for a good "hello world" example.
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Building Java web applications with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/
antony@claire.co.jp wrote:
>
> 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: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: What is the best way to display pictures from a database using Struts
Posted by an...@claire.co.jp.
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: What is the best way to display pictures from a database using
Struts
Posted by Simon Oldeboershuis <so...@outermedia.de>.
Hi 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.
hope this helps
Simon
Ted Husted schrieb:
>
> Struts doesn't actually display anything. This task is delegated to the
> JSPs, or other view rendering system. So the first question is how to
> get the images displayed by a JSP. I'm don't actually know how that
> would work, since HTML expects the images to be in a separate file. You
> may need to look at using PDF or an applet.
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel +1 716 737-3463
> -- http://www.husted.com/struts/
>
> antony@claire.co.jp wrote:
> >
> > 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.
> >
> > Cheers
> >
> > Antony
> >
> > --
> > To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: What is the best way to display pictures from a database using
Struts
Posted by Ted Husted <hu...@apache.org>.
Struts doesn't actually display anything. This task is delegated to the
JSPs, or other view rendering system. So the first question is how to
get the images displayed by a JSP. I'm don't actually know how that
would work, since HTML expects the images to be in a separate file. You
may need to look at using PDF or an applet.
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/
antony@claire.co.jp wrote:
>
> 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.
>
> Cheers
>
> Antony
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>