@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));
} }

kaptcha验证码的更多相关文章

  1. Java实现验证码制作之一Kaptcha验证码

    Kaptcha验证码 是google提供的验证码插件,使用起来相对简单,设置的干扰线以及字体扭曲不易让其他人读取破解. 这里我们需要 导入一个 kaptcha-2.3.jar  下载地址:http:/ ...

  2. kaptcha验证码插件的使用

    kaptcha 是一个非常实用的验证码生成工具.有了它,你可以生成各种样式的验证码,因为它是可配置的.kaptcha工作的原理是调用 com.google.code.kaptcha.servlet.K ...

  3. kaptcha 验证码组件使用

    kaptcha 验证码组件使用简介   kaptcha 是一个非常实用的验证码生成工具.有了它,你可以生成各种样式的验证码,因为它是可配置的.kaptcha工作的原理是调用 com.google.co ...

  4. KAPTCHA验证码使用步骤

    使用kaptcha可以方便的配置: · 验证码的字体 · 验证码字体的大小 · 验证码字体的字体颜色 · 验证码内容的范围(数字,字母,中文汉字!) · 验证码图片的大小,边框,边框粗细,边框颜色 · ...

  5. kaptcha验证码的使用

    使用kaptcha可以方便的配置: 验证码的字体 验证码字体的大小 验证码字体的字体颜色 验证码内容的范围(数字,字母,中文汉字!) 验证码图片的大小,边框,边框粗细,边框颜色 验证码的干扰线(可以自 ...

  6. jcaptcha和kaptcha验证码使用入门【转】

    jcaptcha和kaptcha验证码使用入门 一.jcaptcha验证码使用 jcaptcha使用默认样式生成的验证码比较难以识别,所以需要自定义验证码的样式,包括,背景色.背景大小.字体.字体大小 ...

  7. kaptcha验证码实现,配合spring boot使用

    一.kaptcha介绍 Kaptcha是谷歌放在github上的一个验证码jar包,我们可以简单配置属性实现验证码的验证功能. kaptcha参数设置如下所示: Constant 描述 默认值 kap ...

  8. google kaptcha 验证码的使用

    这边演示下idea+maven+servlet实现谷歌的kaptcha验证码的使用: web.xml, 这边主要是kaptcha验证器, <!DOCTYPE web-app PUBLIC &qu ...

  9. google kaptcha 验证码组件使用简介

    kaptcha 是一个非常实用的验证码生成工具.有了它,你可以生成各种样式的验证码,因为它是可配置的.kaptcha工作的原理是调用 com.google.code.kaptcha.servlet.K ...

  10. kaptcha验证码组件使用简介

    Kaptcha是一个基于SimpleCaptcha的验证码开源项目. 官网地址:http://code.google.com/p/kaptcha/ kaptcha的使用比较方便,只需添加jar包依赖之 ...

随机推荐

  1. 爬虫:Scrapy16 - Spider Contracts

    Scrapy 通过合同(contract)的方式来提供了测试 spider 的集成方法. 可以硬编码(hardcode)一个样例(sample)url,设置多个条件来测试回调函数处理 response ...

  2. Android开发中Parcelable接口的使用方法

    在网上看到很多Android初入门的童鞋都在问Parcelable接口的使用方法,小编参考了相关Android教程,看到里面介绍的序列化方法主要有两种分别是实现Serializable接口和实现Par ...

  3. 1031. 高一学堂 (at)

    题目描述 在美丽的中山纪念中学里面,有一座高一学堂.所谓山不在高,有仙则名:水不在深,有龙则灵.高一学堂,因为有了yxr,就成了现在这个样子 = =. 由于yxr的语言太过雷人,每次他发微往往都会有一 ...

  4. codeforces838D - Airplane Arrangements

    太妙啦! 我们把座位摆成一个环,在添加另一个座位,表示坐了这个位置就会有人生气,那么我们现在要求的就是没人坐它的方案数Ans,但是这个并不好求,我们发现对于每个位置,它们的Ans都是一样的,而且Ans ...

  5. 刷题总结——子串(NOIP2015)

    题目: 题目背景 NOIP2015 提高组 Day2 T2 题目描述 有两个仅包含小写英文字母的字符串 A 和 B .现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其在 ...

  6. 浅谈android Socket 通信及自建ServerSocket服务端常见问题

    摘  要:TCP/IP通信协议是可靠的面向连接的网络协议,它在通信两端各建立一个Socket,从而在两端形成网络虚拟链路,进而应用程序可通过可以通过虚拟链路进行通信.Java对于基于TCP协议的网络通 ...

  7. WIN8下笔记本共享热点的设置

    C:\windows\system32>netsh wlan start hostednetwork 无法启动承载网络. 组或资源的状态不是执行请求操作的正确状态. 解决方法: http://j ...

  8. Linux内核实践之序列文件【转】

    转自:http://blog.csdn.net/bullbat/article/details/7407194 版权声明:本文为博主原创文章,未经博主允许不得转载. 作者:bullbat seq_fi ...

  9. c专家编程读书笔记

    无论在什么时候,如果遇到malloc(strlen(str));,几乎可以直接断定他是错误的,而malloc(strlen(str)+1):才是正确的: 一个L的NUL哟关于结束一个ACSII字符串: ...

  10. hdu 5155(递推)

    Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...