Dynamic images with JSP

Hello,

I am using NetBeans to make a WebApp. I have an image to display on Page3.jsp that is generated during the navigation from the previous page, Page2.jsp. This image is a png file, and is unique graph generated for each visitor. Is there a simple way to display dynamically created images? I have searched for tutorials and asked my good pal Google but to no avail.

(FYI: At present, I am saving the images in a folder I have created beneath the 'web' folder, called 'web/images'. Netbeans asks me if I want to reload the image only after the previous, old image has been sent out by the server. I am producing and creating the image with the button_action method of Page2.jsp that then sends the user to Page3.jsp, where the image is to be displayed. Once the image is reloaded, I can refresh the web page and the correct image appears.)

Any help would be greatly appreciated.

Thanks,

Taivo

[937 byte] By [taivoa] at [2007-11-27 11:08:24]
# 1

Although I have never implemented this, I know it is possible and I can point you in the right direction. If you already have the code to create the .png image, it shouldn't be too difficult to modify the image code into a servlet to serve nothing but the image (and leave rest of the html in place). Just as the page is writen to an output stream from the request for page.jsp (by the servlet created by the jsp parser), a request for an image can be handled by a servlet.

//this is in page3.jsp as plain HTML

<img src="/servlet/graph?user=aUser" />

This servlet (graph.class) draws ths image, but instead of writing it to a file, writes it to the response stream.

Hope this helps,

Bamkin

bamkin-ov-lestaa at 2007-7-29 13:28:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...