生成一个验证码
来源:互联网 发布:淘宝禁售商品答案 编辑:程序博客网 时间:2024/05/26 02:19
package response_test;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.image.BufferedImage;import java.io.IOException;import java.util.Random;import javax.imageio.ImageIO;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.dsna.util.images.ValidateCode;public class Response_demo4 extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//test(response);//告诉客户端不要使用缓存response.setHeader("pragma", "no-cache");response.setHeader("cache-control", "no-cache");response.setIntHeader("expores", 0);//使用ValidateCode.jarValidateCode vc=new ValidateCode(110, 25, 4, 9);String code=vc.getCode();System.out.println(code);//测试vc.write(response.getOutputStream());}private void test(HttpServletResponse response) throws IOException {//告诉客户端不要使用缓存response.setHeader("pragma", "no-cache");response.setHeader("cache-control", "no-cache");response.setIntHeader("expores", 0);int width=110;int height=25;//在内存中创建一个图像对象BufferedImage img =new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);//创建一个画笔Graphics g=img.getGraphics();//给图片添加背景色g.setColor(Color.PINK);g.fillRect(1, 1, width-2, height-2);//设置文本样式g.setColor(Color.BLUE);g.setFont(new Font("宋体", Font.BOLD|Font.ITALIC, 15));//给图片添加文本Random rand=new Random();int position=20;for(int i=0;i<4;i++){g.drawString(rand.nextInt(10)+"", position, 20);position+=20;}for (int i = 0; i < 6; i++) {g.drawLine(rand.nextInt(width), rand.nextInt(height), rand.nextInt(width), rand.nextInt(height));}ImageIO.write(img, "jpg", response.getOutputStream());}public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}}
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>登陆界面</title></head><script>function changeCode(){var img=document.getElementsByTagName("img")[0];img.src="/response_test/demo4?time="+new Date().getTime();}</script><body><form action="#" method="post">用户名: <input type="text" name="" id="" style="width: 139px; "><br>密码: <input type="text" name="" id=""> <br>验证码:<input type="text" name=""><img src="/response_test/demo4" alt="" onclick="changeCode()"><br><input type="submit" name="" id=""></form></body></html>
阅读全文
0 0
- 生成一个验证码
- 生成一个验证码
- 一个好的验证码生成类
- 一个简单的验证码生成程序
- 一个生成验证码的程序
- 随机生成一个验证码图片
- 一个简单的验证码生成方法
- 一个简单的PHP生成验证码
- 如何生成一个安全的验证码
- 一个python的验证码生成类
- php 简易的一个 验证码 生成
- js随机生成一个验证码
- php封装一个生成图像验证码
- 用java代码 生成验证码的一个示例类
- 网站登录页面,验证码的一个生成方法
- 一个随机生成验证码的jsp serlevt
- 验证码制作之一:随机生成一个四位数字
- 一个在网上搜索到的验证码生成代码
- luoguP1256 显示图像 题解
- SQL基础(三)
- eclipse svn 忽略文件夹
- mysql中把一个表的数据批量导入另一个表中
- 5. Longest Palindromic Substring(最长回文子串)
- 生成一个验证码
- jrebel6 启动时报error:JRebel bootclasspath not specified!
- MFC子窗口和父窗口
- python中optparse模块用法
- zTree-jQuery树插件
- 【最大流 && 拆点限流】POJ
- response.setCharacterEncoding("UTF-8")不生效的原因及解决方法
- 散列表(下)——分离链接法
- adb无法识别安卓设备