博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kaptcha验证码
阅读量:7077 次
发布时间:2019-06-28

本文共 3404 字,大约阅读时间需要 11 分钟。

 

@Action("/validimg")public String validimg() throws Exception {        genernateCaptchaImage();        return null;}

 

 

protected void genernateCaptchaImage() throws IOException {        response.setHeader("Cache-Control", "no-store");        response.setHeader("Pragma", "no-cache");        response.setDateHeader("Expires", 0);        response.setContentType("image/jpeg");        ServletOutputStream out = response.getOutputStream();        try {            String captchaId = request.getSession(true).getId();            LOGGER.info("当前生产验证码的sessionId为: "+captchaId);            BufferedImage challenge = (BufferedImage) CaptchaServiceSingleton.getInstance().getChallengeForID(                    captchaId, request.getLocale());            ImageIO.write(challenge, "jpg", out);            out.flush();        } catch (CaptchaServiceException e) {        } finally {            out.close();        }    }

 

 

 

/** * JCaptcha的单例 *  * @author fuxingxign */public class CaptchaServiceSingleton {    private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService(            new FastHashMapCaptchaStore(), new RdImageEngine(), 180, 100000, 75000);    /*     * private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService( new     * FastHashMapCaptchaStore(), new GMailEngine(), 180, 100000 , 75000);     */    public static ImageCaptchaService getInstance() {        return instance;    }}

 

 

 

import java.awt.Color;import java.awt.Font;import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;import com.octo.captcha.component.image.color.RandomRangeColorGenerator;import com.octo.captcha.component.image.fontgenerator.FontGenerator;import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;import com.octo.captcha.component.image.textpaster.RandomTextPaster;import com.octo.captcha.component.image.textpaster.TextPaster;import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;import com.octo.captcha.component.image.wordtoimage.WordToImage;import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;import com.octo.captcha.component.word.wordgenerator.WordGenerator;import com.octo.captcha.engine.image.ListImageCaptchaEngine;import com.octo.captcha.image.gimpy.GimpyFactory;public class RdImageEngine extends ListImageCaptchaEngine {    @Override    protected void buildInitialFactories() {        WordGenerator wgen = new RandomWordGenerator("abcdefghijklmnopqrstuvwxyz");        RandomRangeColorGenerator cgen = new RandomRangeColorGenerator(new int[] { 0, 100 }, new int[] { 0, 100 },                new int[] { 0, 100 });        TextPaster textPaster = new RandomTextPaster(Integer.valueOf(4),Integer.valueOf(4), cgen, true);        BackgroundGenerator backgroundGenerator = new UniColorBackgroundGenerator(Integer.valueOf(80), Integer.valueOf(37),                Color.WHITE);        Font[] fontsList = new Font[] { new Font("Arial", 0, 12), new Font("Tahoma", 0, 12),                new Font("Verdana", 0, 12), };        FontGenerator fontGenerator = new RandomFontGenerator(Integer.valueOf(26),Integer.valueOf(26), fontsList);        WordToImage wordToImage = new ComposedWordToImage(fontGenerator, backgroundGenerator, textPaster);        this.addFactory(new GimpyFactory(wgen, wordToImage));    }}

 

转载地址:http://iopml.baihongyu.com/

你可能感兴趣的文章
使用gdebi去解决安装deb包的时候软件依赖问题
查看>>
SOP 1.6.0 发布,开放平台解决方案项目
查看>>
Java并发编程笔记之AbstractQueuedSynchronizer源码分析
查看>>
AI戒毒?没错,北京开始这么干了
查看>>
第178天:表单验证
查看>>
HTTP配置文件详解(访问控制、虚拟主机、DEFLATE、HTTPS配置
查看>>
数据库分离附加(附日记丢失的处理)
查看>>
开启HDR视觉盛宴:究竟什么视频算得上HDR?
查看>>
阿里云视频点播播放常见问题排查指南
查看>>
Java最全异常讲解
查看>>
Android保持屏幕常亮
查看>>
JS-DOM2级事件对象跨浏览器处理(已封装)
查看>>
用户名和密码校验程序
查看>>
浅析Java RTTI 和 反射的概念
查看>>
Django中用户权限模块
查看>>
Android TransitionDrawable:过渡动画Drawable
查看>>
keras实战项目——CIFAR-10 图像分类
查看>>
数据库变更管理
查看>>
隐私浏览器 Tor Browser 8.0.7 发布,安全更新版本
查看>>
Veeam发布2016年业绩: 同比增长28%,预订总收入达6.07亿美元
查看>>