Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.
(Answer) (Category) Java Apache Project : (Category) Apache JServ 1.0 : (Category) Programming and Misc. Tidbits :
Displaying images with servlets...
----------
From: "Craig R. McClanahan" cmcclanahan@mytownnet.com
To: Java Apache Users java-apache-users@list.working-dogs.com
Subject: Re: displaying images within servlets
Date: Wed, Jul 7, 1999, 3:07 PM


--

Allan Stuart Meidlein wrote:

> --
>
> Hello All,
>
> I have searched through the FAQ-o-Matic and have only found one entry
> related to images and servlets.  What I need to do is display some
> simple images within the servlet along with text; I understand that the
> HTML content type must be set to 'text/gif" or whatever format, but I'm
> confused at how I can have text and images on the same page when my
> content type is already set at "text/html."
>
> Thanks in advance.
>
> Allan
>

First, the content type for a GIF image is "image/gif", not "text/gif".

You are correct that you can not mix text and image output in the same
page.  What you need to do is include a normal image link, like this:

    <img src="xxxxx">

in the text output of your servlet (just as if you were authoring a
stand-alone HTML page).

Now, what is "xxxxx"?  Well, if the images you are talking about are
available at a particular URL on your web server, just use that URL and
the browser will download it in the usual way.

It is also possible to have a servlet dynamically create an image, by
using a URL that points back at your servlet.  An example is where you
might be constructing a graph image on the fly, using some graphics
library.  You will need to do something in the URL to tell your servlet to
return the image instead of a text page.

The browser will request this URL on a separate request from the one that
is causing your page to be created, so you never have to mix text and
binary data on the same request.

Craig McClanahan
[Append to This Answer]
Previous: (Answer) How to maintain session state in remote static html files...
Next: (Answer) How do I debug my servlets?
This document is: http://java.apache.org/faq/?file=241
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.709.
Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.