Googlekaptcha简单方便的验证码生成工具
kaptcha 简单方便的验证码生成工具
分类: java2010-09-11 15:13 5232人阅读 评论(0) 收藏 举报
kaptcha是一个非常实用的验证码生成工具,有了它,你可以生成各种样式的验证码,因为它是可配置的。
kaptcha工作的原理是调用de.kaptcha.servlet.KaptchaServlet,生成一个图片。同时将生成的验证码字符串放到HttpSession中。
kaptcha可以配置一下信息:
验证码的字体
验证码字体的大小
验证码字体的字体颜
验证码内容的范围(数字,字母,中文汉字!)
验证码图片的大小,边框,边框粗细,边框颜
验证码的干扰线(可以自己继承de.kaptcha.NoiseProducer写一个自定义的干扰线)
验证码的样式(鱼眼样式、3D、普通模糊……当然也可以继承de.kaptcha.GimpyEngine自定义样式)
……
详细信息请看下面的l文件
下面介绍一下用法:
1.首先去下载jar:le/p/kaptcha/
2.建立一个web项目,导入kaptcha-2.3.jar到环境变量中。
3.配置l文件
其实就是配置de.kaptcha.servlet.KaptchaServlet
[xhtml] view plaincopy
1.<?xml version="1.0" encoding="UTF-8"?>
2.<web-app xmlns="/xml/ns/j2ee" xmlns:xsi="/2001/XMLSchema-instance"
3.xsi:schemaLocation="/xml/ns/j2ee /xml/ns/j2ee/web-app_2_4.xsd"
4.version="2.4">
5.<servlet>
6.<servlet-name>Kaptcha</servlet-name>
7.<servlet-class>de.kaptcha.servlet.KaptchaServlet</servlet-class>
8.<init-param>
9.<description> Border around kaptcha. Legal values are yes or no. </description>
10.<param-name>kaptcha.border</param-name>
11.<param-value>no</param-value>
12.</init-param>
13.<init-param>
14.<description>Color of the border. Legal values are r,g,b (and optional alpha) or white,black,blue. </description>
15.<param-name>lor</param-name>
16.<param-value>red</param-value>
17.</init-param>
18.<init-param>
19.<description>Thickness of the border around kaptcha. Legal values are > 0. </description>
20.<param-name>kaptcha.border.thickness</param-name>
21.<param-value>5</param-value>
22.</init-param>
23.<init-param>
24.<description>Width in pixels of the kaptcha image. </description>
25.<param-name>kaptcha.image.width</param-name>
26.<param-value>80</param-value>
27.</init-param>
28.<init-param>
29.<description>Height in pixels of the kaptcha image. </description>
30.<param-name>kaptcha.image.height</param-name>
31.<param-value>40</param-value>
32.</init-param>
33.<init-param>
34.<description>The image producer. </description>
35.<param-name>kaptcha.producer.impl</param-name>
36.<param-value>de.kaptcha.impl.DefaultKaptcha </param-value>
37.</init-param>
38.<init-param>
39.<description>The text producer. </description>
40.<param-name>producer.impl</param-name>
41.<param-value>impl.DefaultTextCreator</param-value>
42.</init-param>
43.<init-param>
44.<description>The characters that will create the kaptcha. </description>
45.<param-name>producer.char.string</param-name>
46.<param-value>abcde2345678gfynmnpwx </param-value>
47.</init-param>
48.<init-param>
49.<description>The number of characters to display. </description>
50.<param-name>producer.char.length</param-name>
51.<param-value>5</param-value>字符串函数模拟注册
52.</init-param>
53.<init-param>
54.<description>A list of comma separated font names.</description>
55.<param-name>producer.font.names</param-name>
56.<param-value>Arial, Courier</param-value>
57.</init-param>
58.<init-param>
59.<description>The size of the font to use. </description>
60.<param-name>producer.font.size</param-name>
61.<param-value>23</param-value>
62.</init-param>
63.<init-param>
64.<description>The color to use for the font. Legal values are r,g,b. </description>
65.<param-name>lor</param-name>
66.<param-value>black</param-value>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论