ServletExample.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:3k
源码类别:
OA系统
开发平台:
Java
- ////////////////////////////////////////////////////////////////
- // ServletExample.java
- ////////////////////////////////////////////////////////////////
- import cn.com.fcsoft.chart.*;
- import java.awt.*;
- import javax.servlet.*;
- //import Acme.JPM.Encoders.*;
- import cn.com.fcsoft.chart.jpeg.JpegEncoder;
- import java.io.UnsupportedEncodingException;
- /**
- * This class implements a servlet, not using the standard ChartServlet
- * class found in chartServer.jar. If you have Tomcat installed and started
- * and the ServletExample class in your CLASSPATH, access the servlet through
- * http://localhost:8080/examples/servlet/com.objectplanet.chart.examples.ServletExample
- *
- * @author Bjorn J. Kvande.
- */
- public class ServletExample extends GenericServlet {
- /**
- * The service.
- */
- public void service(ServletRequest req, ServletResponse res)
- throws ServletException, java.io.IOException
- {
- res.setContentType("image/jpeg; charset=gbk");
- //create the chart
- BarChart chart = new BarChart(5);
- double[] values1 = new double[] {100, 200, 300, 400, 500};
- double[] values2 = new double[] {400, 300, 100, 200, 200};
- chart.setSeriesCount(2);
- chart.setSampleValues(0, values1);
- chart.setSampleValues(1, values2);
- chart.setBarType(BarChart.STACKED_BARS);
- chart.setRange(0, 1000);
- chart.set3DModeOn(true);
- chart.setTitle("直方图组件实例");
- chart.setTitleOn(true);
- chart.setValueLinesOn(true);
- chart.setMultiColorOn(true);
- // produce the gif image
- Image image = chart.getImage(300,200);
- ServletOutputStream out = (ServletOutputStream)res.getOutputStream();
- // GifEncoder gif = new GifEncoder (image, out);
- // gif.encode();
- // out.flush();
- // res.setContentType("image/gif");
- JpegEncoder jpegencoder = new JpegEncoder(image, 75, out);
- jpegencoder.Compress();
- out.flush();
- //res.setContentType("image/jpeg;charset=UTF-8");
- //return "image/jpeg";
- return;
- }
- public static String default2Gb(String strIn)
- {
- String strReturn;
- try
- {
- strReturn = new String(strIn.getBytes(), "GBK");
- return strReturn;
- }
- catch(UnsupportedEncodingException e)
- { return null;}
- catch(NullPointerException e)
- { return null;}
- }
- public static String Latin2Gb(String strIn)
- {
- String strReturn;
- try
- {
- strReturn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
- return strReturn;
- }
- catch(UnsupportedEncodingException e)
- { return null;}
- catch(NullPointerException e)
- { return null;}
- }
- public static String UTF82GB(String strIn)
- {
- String strReturn;
- try
- {
- strReturn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
- return strReturn;
- }
- catch(UnsupportedEncodingException e)
- { return null;}
- catch(NullPointerException e)
- { return null;}
- }
- }