Could your browser be caching the image? Put some debug code in the servlet to print to the console. It should print each time a request is sent.
-Richard At 09:56 AM 3/20/2002 +0000, you wrote: >Hi ! I copied,compiled and ran the code(Please see the attached mail from a >different thread) and wow !! got a realy intresting Image !!!! > >But i was xpecting that on each subsequent invocation the image will change >as the code uses random no. But the image remains the same. Maybe because >there is no getLastModified(HttpServletRequest) which may have somehow told >the browser to reload the servlet and create a new image. Am i right ? > >Note : If I close and restart the browser, the image changes > >Any comments ? > >-----Original Message----- >From: ���� �������� [mailto:[EMAIL PROTECTED]] >Sent: 20 March 2002 08:53 >To: [EMAIL PROTECTED] >Subject: Re: Dynamic images and graphs using servlets > > >V> Does anybody have a good article/source as how to create dynamic >V> images/graphs using servlets. > >try this example > >import javax.servlet.*; >import javax.servlet.http.*; >import java.io.*; >import java.awt.*; >import java.awt.image.*; >import com.sun.image.codec.jpeg.*; >import java.util.*; > >public class MakeImage extends HttpServlet { > > public void doGet( > HttpServletRequest request, > HttpServletResponse response) > throws ServletException, IOException { > > response.setContentType("image/jpeg"); > > // Create image > int width=200, height=200; > BufferedImage image = new BufferedImage( > width, height, BufferedImage.TYPE_INT_RGB); > > // Get drawing context > Graphics g = image.getGraphics(); > > // Fill background > g.setColor(Color.white); > g.fillRect(0, 0, width, height); > > // Create random polygon > Polygon poly = new Polygon(); > Random random = new Random(); > for (int i=0; i < 20; i++) { > poly.addPoint(random.nextInt(width), > random.nextInt(height)); > } > > // Fill polygon > g.setColor(Color.cyan); > g.fillPolygon(poly); > > // Dispose context > g.dispose(); > > // Send back image > ServletOutputStream sos = > response.getOutputStream(); > JPEGImageEncoder encoder = > JPEGCodec.createJPEGEncoder(sos); > encoder.encode(image); > > } >} > >Delivering Dynamic Images from JavaServer PagesTM (JSPTM) Technology. >http://java.sun.com/jdc/JDCTechTips/2001/tt0821.html > >-- >Best regards, >Yuriy > >___________________________________________________________________________ >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 > >___________________________________________________________________________ >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 ___________________________________________________________________________ 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
