I am thinking of trying servlet chaining. show the image in an html page and call that servlet via another servlet using the servlet chaining mechanism. hopefully that should work
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
How is that supposed to work? The only images that will display on an HTML page are images created with an img tag unless you add the Image object to an applet.
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
Originally posted by Thomas Paul: You can't. An AWT Image can only be displayed in an Applet or a Frame.
Bzzzt. Images work just as well for drawing offline images. Let's start at the client -- you incorporate an image using an <IMG> tag. Point this tag at a servlet. This servlet will generate the binary stream that represents the image as output. The best thing is to communicate all the parameters necessary to generate the image to your servlet, rather than pre-generate the image and leaving it to consume resources on your server until the client requests it. These parameters can sit either in image URL parameters or in your session context. The servlet then generates the image. Make sure you have a javax.awt.image.BufferedImage. Use the graphics context or whatever to draw on it what you want. The next step is to convert the image to something the browser understands. Sun's JDK only ships with a JPEG encoder afaik (com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder()). This encoder takes your BufferedImage, encodes it and writes it to an OutputStream. The response.getOutputStream() will do fine. Be sure to set your response headers before writing the image especially response.setContentType(). - Peter
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
of course you can do it! You can do it in Perl so why shouldn't you be able to do it in Java? Here is a sample program:
Here's the HTML: <HTML> <HEAD> <TITLE>Image Display HTML</TITLE> </HEAD> <BODY bgcolor="black"> <br> <br> <br> <center><img src="/servlet/ImageDisplayer"></center> </BODY> </HTML> [This message has been edited by Thomas Paul (edited February 16, 2001).]