response-实现验证码
来源:互联网 发布:薛之谦淘宝衣服贵吗 编辑:程序博客网 时间:2024/06/05 15:11
public static final int WIDTH =120; public static final int HEIGHT= 25; /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); //1.设置背景色 setBackGround(g); //2.设置边框 setBorder(g); //3.画干扰线 drawRandomLine(g); //4.写随机数 drawRandomNum((Graphics2D)g); //5.写给浏览器 response.setContentType("image/jpeg"); //发头控制浏览器不要缓存 response.setDateHeader("expries",-1); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); ImageIO.write(image, "jpg", response.getOutputStream()); } private void drawRandomNum(Graphics2D g) { g.setColor(Color.RED); g.setFont(new Font("宋体",Font.BOLD,20)); String base = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a"; //{\u4e00-\u9fa5} int x=5; for (int i = 0; i < 4; i++) { int degree = new Random().nextInt()%30; String ch =base.charAt(new Random().nextInt(base.length()))+""; g.rotate(degree*Math.PI/180,x,20);//设置旋转角度 g.drawString(ch, x, 20); g.rotate(-degree*Math.PI/180,x,20); x+=30; } } private void drawRandomLine(Graphics g) { g.setColor(Color.GREEN); for (int i = 0; i < 5; i++) { int x1=new Random().nextInt(WIDTH); int y1=new Random().nextInt(HEIGHT); int x2=new Random().nextInt(WIDTH); int y2=new Random().nextInt(HEIGHT); g.drawLine(x1, y1, x2, y2); } } private void setBorder(Graphics g) { g.setColor(Color.BLUE); g.drawRect(1, 1, WIDTH-2,HEIGHT-2); } private void setBackGround(Graphics g) { g.setColor(Color.WHITE); g.fillRect(0, 0, WIDTH, HEIGHT); }
0 0
- response-实现验证码
- response实现验证码
- 菜鸟学Android笔记(三十一):Response实现验证码
- 深入学习请求响应(二)---response实现验证码
- response 生成图片验证码
- response生成图片验证码
- response生成图片验证码
- Response生成图片验证码
- response 生成图片验证码
- response及验证码例子
- 深入体验JavaWeb开发内幕之Response对象操作实例之通过Response实现图片验证码
- jsp图片验证码实现及getOutputStream() has already been called for this response异常
- jsp图片验证码实现及getOutputStream() has already been called for this response异常
- jsp图片验证码实现及getOutputStream() has already been called for this response异常
- 用jsp页面实现验证码出现getOutputStream() has already been called for this response
- 用jsp页面实现验证码出现getOutputStream() has already been called for this response
- jsp图片验证码实现及getOutputStream() has already been called for this response异常
- 利用服务器response生产随机验证码
- 闪存浪潮下不得不知的知识(2)-颗粒篇
- 测试 __try, __finally, __except
- 选择排序
- 通过C#代码实现空间离散点的克里金(kriging)插值(一) 计算原理
- android之旅17 四大组件之服务基本概念
- response-实现验证码
- Swift 实现 iOS 类似微信输入框跟随键盘弹出的效果
- LeetCode: 008-Contains Duplicate
- 静态成员变量初始化问题
- 【cocos2d-x 3.x 学习与应用总结】3: CallFunc系列
- IM系统框架
- 给JFinal添加 Sqlite 数据库支持
- 点击弹出导航导航按钮菜单
- 两种网络数据格式的比较