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. Spring的AOP机制---- AOP的注解配置---- AOP的注解配置

    3333隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约隐隐约约噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢 ...

  2. Android 新浪微博开放平台应用 android签名怎么获得

    方法一: 通过命令行,直接生成MD5值 keytool -list -v -keystore keystorefile -storepass 其中keytool为jdk自带工具:keystorefil ...

  3. 【PL/SQL】匿名块、存储过程、函数、触发器

    名词解释 子程序:PL/SQL的过程和函数统称为子程序. 匿名块:以DECLARE或BEGIN开始,每次提交都被编译.匿名块因为没有名称,所以不能在数据库中存储并且不能直接从其他PL/SQL块中调用. ...

  4. mssql for VSCode Guide

    前言 mssql 出自微软自己的 Visual Studio Code 开源插件,代码托管于 GitHub 上. 不过需要注意的一点是,使用 insert into 语句新增的数据...中文是会乱码的 ...

  5. Table边框使用总结 ,只显示你要显示的边框

    表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间隔, ...

  6. (1)dotnet开源电商系统-brnshop&brnMall 和老外开发的nopCommerce(dotnet两套电商来PK--第一篇)

    一直想做电商软件,但是实在不想学PHP了,所以前后关注了这两个开源电商系统.一个是国人出品的,一个据说是俄罗斯人写得(不知道对不对).目前两个开源软件都在学习了解中,以下的博文可能会涉及到这两套系统, ...

  7. Higher-Order Functions and Lambdas

    https://kotlinlang.org/docs/reference/lambdas.html

  8. fileupload 上传控件

    <div> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:But ...

  9. Javascript语法,变量类型,条件,循环语句,函数,面向对象

    1.JavaScript代码革两种存在形式: <!-- 方式一 --> <script type='txt/javascript' src='/js/comment.js'>& ...

  10. Spring Cloud Alibaba、Spring Boot、Spring Cloud对应版本关系

    Spring Boot Spring Cloud Spring Cloud Alibaba 2.1.x Greenwich 0.9.x 2.0.x Finchley 0.2.x 1.5.x Edgwa ...