request对象和response对象(4)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-10 12:18 点击:次
p> BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
p> //得到属于该图片的画笔:Graphics();
p> Graphics g = image.getGraphics();
p> //画边框
p> g.setColor(Color.BLUE);
p> g.drawRect(0, 0, width, height);
p> //填充背景色
p> g.setColor(Color.YELLOW);
p> g.fillRect(1, 1, width-2, height-2);
p> //画干扰线
p> g.setColor(Color.GRAY);
p> Random r = new Random();
p> for(int i=0; i<10; i++)
p> g.drawLine(r.nextInt(width), r.nextInt(height), r.nextInt(width), r.nextInt(height));
p> //随机数字
p> g.setColor(Color.RED);
p> g.setFont(new Font("宋体",Font.BOLD|Font.ITALIC,20));
p> int x = 23;
p> for(int i=0; i<4; i++){
p> g.drawString(r.nextInt(10)+"", x, 20);
p> x = x+20;
p> }
p> //输出到浏览器的页面上:ImageIO
p> ImageIO.write(image, "jpg", response.getOutputStream());
p> }
p>
p> public void doPost(HttpServletRequest request, HttpServletResponse response)
p> throws ServletException, IOException {
p> doGet(request,response);
p> }
p>}
p>复制代码
p>4.定时刷新
p>
p>复制代码
p>package cn.lsl.response;
p>
p>import java.io.IOException;
p>import java.io.PrintWriter;
p>import java.util.Random;
p>import javax.servlet.ServletException;
p>import javax.servlet.http.HttpServlet;
p>import javax.servlet.http.HttpServletRequest;
p>import javax.servlet.http.HttpServletResponse;
p>
p>public class ResponseDemo4 extends HttpServlet {
p>
p> public void doGet(HttpServletRequest request, HttpServletResponse response)
p> throws ServletException, IOException {
p> test2(response);
p> }
p>
p> //定时刷新到自己
p> private void test1(HttpServletResponse response) throws IOException{
p> Random r = new Random();
p> int i = r.nextInt();
p> response.setIntHeader("Refresh", 1);
p> response.getOutputStream().write((i+"").getBytes());
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>