package com.gen;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random; public class imageController extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置浏览器三秒刷新一次
resp.setHeader("refresh", "3");
//在内存中创建一个图片
BufferedImage bufferedImage = new BufferedImage(100, 30, BufferedImage.TYPE_INT_RGB);
//获取图片
Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
//设置背景颜色
graphics.setColor(Color.white);
//设置字体
graphics.setFont(new Font(null,Font.BOLD,30));
graphics.drawString(makenum(), 0, 30);
//指定浏览器要打开的方式
resp.setContentType("image/jpeg");
//设置浏览器无缓存
resp.setDateHeader("expires",-1);
resp.setHeader("Cache-control","no-cache");
resp.setHeader("Pragma","no-cache");
//输出客户端
ImageIO.write(bufferedImage,"jpg",resp.getOutputStream());
} private String makenum() {
int num = new Random().nextInt(9999);
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 4.; j++) {
sb.append("0");
}
return sb.toString() + num;
} @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}

最新文章

  1. spring hadoop 访问hbase入门
  2. Hadoop概括——学习笔记&lt;一&gt;转
  3. 内存分析_.Net垃圾回收介绍
  4. sql server2008附加数据库5120错误
  5. Java学习之InputStream中read()与read(byte[] b)
  6. linux经常使用(一)linux 安装配置 jdk之 找不到安装文件文件夹及source /etc/profile 报unexpected end of file 错误 解决
  7. Moss、SharePoint数据库迁移问题(转)
  8. js缓冲运动
  9. 腾讯AlloyTeam发布AlloyLever - 开发调试发布错误监控上报用户问题定位尽在1kb代码
  10. [Inside HotSpot] C1编译器工作流程及中间表示
  11. git基本概念
  12. Apache 项目列表功能分类便于技术选型
  13. 解决 Ubuntu 经常 卡死
  14. ubuntu16.04系统彻底卸载mysql,并源码免编译重装MySQL的步骤
  15. Sublime text3常用的插件功能和常用的快捷键
  16. MVC与WebApi中的异常统一处理
  17. NSIS Error:Error writing temporary file. Make sure your temp folder is valid的解决办法
  18. hdu1198(模拟搜索)
  19. centos配置网络
  20. The OAuth 2.0 Authorization Framework: Bearer Token Usage

热门文章

  1. 教你解决虚拟机用不了USB设备的苦恼。
  2. 9月22日内容总结——计算机五大组成部分详解、编程语言及发展史、python解释器安装与环境变量设置
  3. 基于APIView写接口
  4. 【笔记向】package.json main 作用
  5. Vue30 过度与动画
  6. ubuntu16.04安装官方cartographer
  7. Xlight安装与使用
  8. PostgreSQL性能优化综合案例 - 1
  9. Linux操作命令(八)1.sort命令 2.uniq命令 3.join命令
  10. Vue ref属性