Hi,
I'm referring to this posting:
>Date: Mon, 19 Oct 1998 13:03:50 -0600
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>Sender: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>From: Kurt Williams <[EMAIL PROTECTED]>
>Subject: Re: Loading images and reading files
>Content-Type: text/plain
>Place an image tag in your HTML that references your image-serving
>Servlet. For example, if your servlet is called ImageServlet and it
>takes two parameters (height and width of the image) you could place the
>following tag inside your HTML:
>
><img src="\servlet\ImageServlet?height=150&width=300">
>
>Then, in the doGet() or doService() method of your servlet, set the
>response content type to "image/gif". You can then send the bytes of
>your image out through the response ServletOutput Stream. For example,
>if you have a method called writeImageBytes(OutputStream out) in
>ImageServer, you might have the following code in your "doService()"
>method:
>
>public void doService(HttpServletRequest req, HttpServletResponse res)
>{
> res.setContentType("image/gif")
> ServletOutputStream out = res.getOutputStream();
>
> writeImageBytes(out); // writes gif-encoded bytes to the output
>stream
> out.flush();
> out.close();
>}
I'm using JavaMail to read a MimeMessage. One Part of the mail contains an
image (image/jpeg). I can create an InputStream for this image. But if I
simply write the bytes to the ServletOutputStream it'll only appear a
broken-image symbol.
How am I to implement writeImageBytes()? Currently I'm using:
response.setContentType("image/jpeg");
ServletOutputStream sos = response.getOutputStream();
// Part pa is the Part of the mail which contains the image
InputStream is = pa.getInputStream();
int c;
while ((c = is.read()) != -1) {
sos.print(c);
}
What is wrong with that? I can't imagine that it's so difficult...
thx in advance
Christian
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html