1.改动CaptchaServiceSingleton类。使用带參构造方法来创建DefaultManageableImageCaptchaService对象。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">

这里我自己定制了一个验证码生成器MyImageEngine,代码例如以下:
package com.xhc.jcaptcha;

import com.octo.captcha.service.captchastore.FastHashMapCaptchaStore;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
import com.octo.captcha.service.image.ImageCaptchaService; public class CaptchaServiceSingleton {
private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService(new FastHashMapCaptchaStore(), new MyImageEngine(), 180,
100000, 75000);
public static ImageCaptchaService getInstance(){
return instance;
}
}

2.MyImageEngine类

package com.xhc.jcaptcha;
import java.awt.Color;
import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.LineRandomTextPaster;
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.FileDictionary;
import com.octo.captcha.component.word.wordgenerator.ComposeDictionaryWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory;
public class MyImageEngine extends ListImageCaptchaEngine {
@Override
protected void buildInitialFactories() {
WordGenerator dictionnaryWords = new ComposeDictionaryWordGenerator(
new FileDictionary("toddlist"));
/* //BaffleRandomTextPaster类生成的是带干扰点的随机验证码贴纸,这里表示最少4个,最多5个字母。蓝色。1个干扰点,干扰点为黄色
TextPaster randomPaster = new BaffleRandomTextPaster(new Integer(4),
new Integer(5), Color.blue, new Integer(1), Color.yellow);*/
//LineRandomTextPaster类生成的是带干扰线的随机验证码贴纸。。。
TextPaster randomPaster = new LineRandomTextPaster(new Integer(4),
new Integer(5),Color.blue, new Integer(1),Color.pink); /*//背景大小及样式设置,UniColorBackgroundGenerator类生成的是统一背景。这里背景统一是lightGray颜色
//宽度为180,高度为50。 BackgroundGenerator back = new UniColorBackgroundGenerator(new Integer(
180), new Integer(50), Color.lightGray);*/
/* //FunkyBackgroundGenerator类生成的是炫酷背景
BackgroundGenerator back = new FunkyBackgroundGenerator(new Integer(
180), new Integer(50));*/
//GradientBackgroundGenerator类生成的是颜色渐变的背景
BackgroundGenerator back = new GradientBackgroundGenerator(new Integer(
180), new Integer(50),Color.gray,Color.yellow); /* //字体设置,RandomFontGenerator类生成的是随机字体,这里字体最小为25px,最大为30px
FontGenerator shearedFont = new RandomFontGenerator(new Integer(25),
new Integer(30));*/
//TwistedRandomFontGenerator类生成扭曲的字体
FontGenerator shearedFont = new TwistedRandomFontGenerator(new Integer(25),
new Integer(30)); //生成验证码模板图片
WordToImage word2image = new ComposedWordToImage(shearedFont, back,
randomPaster); //把随机生成的验证码和模板放入工厂进行组装生成终于的验证码图片
addFactory(new GimpyFactory(dictionnaryWords, word2image));
}
}

3.jsp代码。web.xml配置,以及登陆校验的servlet与前一遍文章使用jcaptcha插件生成验证码代码一样。能够跳转到那里去查看代码。

4.效果图

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">


jcaptcha进阶的更多相关文章

  1. nodejs进阶(6)—连接MySQL数据库

    1. 建库连库 连接MySQL数据库需要安装支持 npm install mysql 我们需要提前安装按mysql sever端 建一个数据库mydb1 mysql> CREATE DATABA ...

  2. nodejs进阶(4)—读取图片到页面

    我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...

  3. JavaScript进阶之路(一)初学者的开始

    一:写在前面的问题和话 一个javascript初学者的进阶之路! 背景:3年后端(ASP.NET)工作经验,javascript水平一般般,前端水平一般般.学习资料:犀牛书. 如有误导,或者错误的地 ...

  4. nodejs进阶(3)—路由处理

    1. url.parse(url)解析 该方法将一个URL字符串转换成对象并返回. url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) ...

  5. nodejs进阶(5)—接收请求参数

    1. get请求参数接收 我们简单举一个需要接收参数的例子 如果有个查找功能,查找关键词需要从url里接收,http://localhost:8000/search?keyword=地球.通过前面的进 ...

  6. nodejs进阶(1)—输出hello world

    下面将带领大家一步步学习nodejs,知道怎么使用nodejs搭建服务器,响应get/post请求,连接数据库等. 搭建服务器页面输出hello world var  http  =  require ...

  7. [C#] 进阶 - LINQ 标准查询操作概述

    LINQ 标准查询操作概述 序 “标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法.大多数这些方法都在序列上运行,其中的序列是一个对象,其类型实现了IEnumerable<T> ...

  8. Java 进阶 hello world! - 中级程序员之路

    Java 进阶 hello world! - 中级程序员之路 Java是一种跨平台的语言,号称:"一次编写,到处运行",在世界编程语言排行榜中稳居第二名(TIOBE index). ...

  9. C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解

    前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解  ...

随机推荐

  1. python实践

    https://www.cnblogs.com/smallSevens/p/10016045.html --二手房交易记录 https://www.cnblogs.com/xiangyuecn/p/1 ...

  2. Python定制容器

    Python 中,像序列类型(如列表.元祖.字符串)或映射类型(如字典)都是属于容器类型,容器是可定制的.要想成功地实现容器的定制,我们需要先谈一谈协议.协议是什么呢?协议(Protocols)与其他 ...

  3. 前端Canvas思维导图笔记

    看不清的朋友右键保存或者新窗口打开哦!喜欢我可以关注我,还有更多前端思维导图笔记

  4. index seek和index scan 提高sql 效率

    index seek和index scan 提高sql 效率解释解释index seek和index scan:索引是一颗B树,index seek是查找从B树的根节点开始,一级一级找到目标行.ind ...

  5. WEB笔记-让HTML5向下兼容的策略

    //给新标签增加块级元素声明 article,aside,dialog,figure,fotter,header,legend,nav,section{display:block} //添加css兹瓷 ...

  6. Embedded之Stack之三

    Stack Overflow While stacks are generally large, they don't occupy all of memory. It is possible to ...

  7. sql 查询替换字符

    Select  A,B,C  from  Tb1 –查询所有 Select  A,replace(B,’1’,’壹’),C  from   Tb1  替换查询 Tb1 A B C AA1 1 CC A ...

  8. apicloud常用分享方法

    app中经常会有分享的功能,不管是分享商品还是文字还是图片或者是发送给微信好友扣扣好友,一下做一总结. 分享的样式(分享所有的样式模块):MNActionButton. 在apicloud 中添加这个 ...

  9. 【JavaScript游戏开发】使用HTML5 canvas开发的网页版中国象棋项目

    //V1.0 : 实现棋子的布局,画布及游戏场景的初始化 //V2.0 : 实现棋子的颜色改变 //V3.0 :实现所有象棋的走棋规则 //V4.0 : 实现所有棋子的吃子功能 完整的项目源码已经开源 ...

  10. 实验吧writeup

    后台登录 1.看源码有这样一段php代码<!-- $password=$_POST['password']; $sql = "SELECT * FROM admin WHERE use ...