欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

可以动态画图输出的JSP例子

程序员文章站 2022-03-31 09:38:02
<%@ page autoFlush="false"          &...

<%@ page autoFlush="false"
             import="java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*"

%>
<%
out.clear();
response.setContentType("image/jpeg");
response.addHeader("pragma","NO-cache");
response.addHeader("Cache-Control","no-cache");
response.addDateHeader("Expries",0);

int width=640,height=480;
BufferedImage image= new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();

g.setColor(Color.white);
g.fillRect(0,0,width,height);

g.setColor(Color.red);
g.drawString("OK",270,220);

g.drawOval(10,10,100,100);

g.dispose();
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
sos.close();
%>