当前位置: 技术问答>java相关
怎样用jsp画图
来源: 互联网 发布时间:2015-04-22
本文导语: 怎样用jsp画图 | import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import com.sun.image.codec.jpeg.*; import java.awt.image.*; import java.awt.*; public class JPEGServlet extends HttpServlet { //...
怎样用jsp画图
|
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;
public class JPEGServlet extends HttpServlet {
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
BufferedImage image = new BufferedImage(100,100, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.red);
g.drawOval(0, 0, 100,100);
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
//Get Servlet information
public String getServletInfo() {
return "JPEGServlet Information";
}
}
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;
public class JPEGServlet extends HttpServlet {
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
BufferedImage image = new BufferedImage(100,100, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.red);
g.drawOval(0, 0, 100,100);
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
//Get Servlet information
public String getServletInfo() {
return "JPEGServlet Information";
}
}