RE: How to declare Output as Image?

2001-09-07 Thread Kane, David

Andrej,

I think you need to use Response.setContentType...

http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletRespon
se.html#setContentType(java.lang.String)

Dave

-Original Message-
From: Andrej Rosenheinrich
To: [EMAIL PROTECTED]
Sent: 9/7/01 10:39 AM
Subject: 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?

2001-09-07 Thread Denis Haskin

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