⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servletexample.java

📁 一个完整的
💻 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;}
    }      
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -