On Fri, 5 Jul 2002, David Mulligan wrote:

> Date: Fri, 5 Jul 2002 14:24:38 +0100
> From: David Mulligan <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: 'Struts Users Mailing List' <[EMAIL PROTECTED]>
> Subject: RE: Displaying a dynamically created Image.
>
> Use the HttpServletResponse.getOutputStream() to send a stream of the image
> back to the browser.
> Be sure to set the correct content-type of the image first using
> HttpServletResponse.setContentType('image/gif);
> So it will be something like
>
>
> response.setContentType('image/gif);
> OutputStream os = HttpServletResponse.getOutputStream();
>
> BufferedInputStream is = //input stream of image
>
> byte[] bytes = new byte[is.available()];
> is.read(bytes);
>
> OutputStream os = response.getOutputStream();
> os.write(bytes);
>
> Don't forget to close the both the input and output streams!
>

Two more important details:

* The code to do the output will need to be in an Action
  (or a class called by your action).  JSP pages cannot
  include binary output -- the <img> tag will create a
  second request to the URL specified by the "src" attribute.

* When your Action is through writing the binary data,
  return null instead of an ActionForward.  This tells
  the controller that the output for this request has
  already been generated, so no forwarding is needed.

Craig


>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 05, 2002 2:05 PM
> To: [EMAIL PROTECTED]
> Subject: Displaying a dynamically created Image.
>
>
>
> How do I display a dynamically created Image with struts
> without saving it to my local harddisc and link the image on it?
> thanks matthias
>
> ----------------------------------------------------------------------------
> ----------------
> Hanel Matthias
> Fachinformatiker (Anwendungsentwicklung) in Ausbildung
> Logistik World GmbH   Fon:    +49-841-9014-300
> Marie-Curie-Strasse 6 Fax:    +49-841-9014-302
> D- 85055 Ingolstadt           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]>
>
>


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

Reply via email to