1 23 24 package de.progra.charting.servlet; 25 26 import javax.servlet.*; 27 import javax.servlet.http.*; 28 import de.progra.charting.*; 29 import java.io.*; 30 31 48 public class ChartServlet extends HttpServlet { 49 50 52 public void init(ServletConfig config) throws ServletException { 53 super.init(config); 54 55 } 56 57 59 public void destroy() { 60 61 } 62 63 67 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 68 throws ServletException, java.io.IOException { 69 70 String imgType = (String )request.getParameter("imageType"); 71 DefaultChart chart = (DefaultChart)request.getSession(true).getAttribute("chart"); 72 73 ServletOutputStream out = response.getOutputStream(); 75 try { 76 if(chart != null) { 77 if(imgType == null) 78 ChartEncoder.createGIF(out, chart); 79 else if(imgType.equals("gif")) 80 ChartEncoder.createGIF(out, chart); 81 else if(imgType.equals("jpeg")) 82 ChartEncoder.createJPEG(out, chart); 83 else 84 ChartEncoder.createPNG(out, chart); 85 } 86 } catch(EncodingException p) { 87 throw new IOException("An Error occurred encoding the Image file."); 88 } 89 90 100 out.close(); 101 } 102 103 107 protected void doGet(HttpServletRequest request, HttpServletResponse response) 108 throws ServletException, java.io.IOException { 109 processRequest(request, response); 110 } 111 112 116 protected void doPost(HttpServletRequest request, HttpServletResponse response) 117 throws ServletException, java.io.IOException { 118 processRequest(request, response); 119 } 120 121 123 public String getServletInfo() { 124 return "Short description"; 125 } 126 127 } 128 | Popular Tags |