/Users/lyon/j4p/src/net/web/ChartServer.java

1    package net.web; 
2     
3     
4    public class ChartServer { 
5     
6      public static void writeGif( 
7          javax.servlet.http.HttpServletResponse response, 
8          java.awt.Component c) { 
9        try { 
10         writeGif(response, j2d.ImageUtils.getImage(c)); 
11       } catch (java.io.IOException e) { 
12         e.printStackTrace(); 
13       } 
14     } 
15    
16     public static void writeGif( 
17         javax.servlet.http.HttpServletResponse response, 
18         java.awt.Image img) throws java.io.IOException { 
19       response.setContentType("image/ip.gif"); 
20       // avoid caching in gui.browser 
21       response.setHeader("Pragma", "no-cache"); 
22       response.setHeader("Cache-Control", "no-cache"); 
23       response.setDateHeader("Expires", 0); 
24       javax.servlet.ServletOutputStream sos = response.getOutputStream(); 
25       toServlet(img, sos); 
26     } 
27    
28     public static void toServlet(java.awt.Image img, 
29                                  javax.servlet.ServletOutputStream sos) { 
30       // encode the image as a GIF 
31       try { 
32         ip.gif.stills.WriteGIF wg = new ip.gif.stills.WriteGIF(img); 
33         wg.toOutputStream(sos); 
34       } catch (Exception e) { 
35         System.out.println("Save GIF Exception!"); 
36       } 
37     } 
38    
39   } 
40