You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andrej Rosenheinrich <to...@die-titanen.de> on 2001/09/07 16:39:38 UTC
How to declare Output as Image?
Hello,
i have a servlet, getting an BufferedImage, that shall be displayed in
my webpage. for doing this I use the following code:
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
(image is the Buffered Image)
Well, the servlet does something, the title-line even claims that there
is a graphic of a certain size (the right one, btw ;-)), but in the
page is only the url of the servlet :-(
I guess, I somehow have to tell the servlet/outputstream??? that the
upcoming data is an image. right? how can i do this in a servlet? any hints?
TIA
Andrej
Re: How to declare Output as Image?
Posted by Denis Haskin <De...@HaskinFerguson.net>.
Andrej Rosenheinrich wrote:
> Hello,
>
> i have a servlet, getting an BufferedImage, that shall be displayed in
> my webpage. for doing this I use the following code:
>
> ServletOutputStream sos = response.getOutputStream();
> JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
> encoder.encode(image);
>
> I guess, I somehow have to tell the servlet/outputstream??? that the
> upcoming data is an image. right? how can i do this in a servlet? any hints?
You have to tell the client what the content-type of the response is, so add
something like:
response.setContentType("image/jpeg");
Then when the browser gets the response, it looks at the header and says "oh,
it's image data" and knows to render it accordingly.
dwh