- 浏览: 203897 次
- 来自: 深圳
-
文章分类
- 全部博客 (161)
- java (15)
- JSTL (3)
- 分页 (4)
- JDK (1)
- 正则表达式 (1)
- struts (2)
- JS (11)
- Tomcat (7)
- XML (1)
- JSP (7)
- MD5加密 (1)
- log4j (1)
- SVN (11)
- Jquery (2)
- myeclipse (3)
- 聚生网管2011 (1)
- 验证码 (2)
- Hibernate (2)
- Andriod (1)
- 网站测试 (2)
- ajax (1)
- linux (2)
- Spring (4)
- oracle (1)
- 个人所得 (4)
- Html (1)
- CSS (1)
- mysql (15)
- 省市区(县)联动 (2)
- 网页背景音乐 (3)
- FTP服务器搭建 (1)
- FTP (3)
- 404 500错误 (2)
- 网站域名绑定 (1)
- 遇到比较纠结的问题 (1)
- 记住密码 (1)
- QQ在线交谈功能 (1)
- Mail (1)
- java邮件 (1)
- java高并发 (1)
- 注册码 (0)
- HTTP状态码 (1)
- PHP (11)
- DZ论坛 (9)
- dz (1)
- ISAPI_Rewrite3 (1)
- asp (3)
- SEO (1)
- dedecms (2)
最新评论
-
shaode2012:
一个个网上都是宁愿写那么多的代码,文字,也没见到几个愿意用数据 ...
省市区(县)联动代码 -
lqfACCP:
...
Pager标签库(分页显示)详解
kaptcha 简单方便的验证码生成工具
kaptcha是一个非常实用的验证码生成工具,有了它,你可以生成各种样式的验证码,因为它是可配置的。
kaptcha工作的原理是调用com.google.code.kaptcha.servlet.KaptchaServlet,生成一个图片。同时将生成的验证码字符串放到HttpSession中。
kaptcha可以配置一下信息:
验证码的字体
验证码字体的大小
验证码字体的字体颜色
验证码内容的范围(数字,字母,中文汉字!)
验证码图片的大小,边框,边框粗细,边框颜色
验证码的干扰线(可以自己继承com.google.code.kaptcha.NoiseProducer写一个自定义的干扰线)
验证码的样式(鱼眼样式、3D、普通模糊……当然也可以继承com.google.code.kaptcha.GimpyEngine自定义样式)
……
详细信息请看下面的web.xml文件
下面介绍一下用法:
1.首先去官网下载jar:http://code.google.com/p/kaptcha/
2.建立一个web项目,导入kaptcha-2.3.jar到环境变量中。
3.配置web.xml文件
其实就是配置com.google.code.kaptcha.servlet.KaptchaServlet
[xhtml] view plaincopy
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
<init-param>
<description> Border around kaptcha. Legal values are yes or no. </description>
<param-name>kaptcha.border</param-name>
<param-value>no</param-value>
</init-param>
<init-param>
<description>Color of the border. Legal values are r,g,b (and optional alpha) or white,black,blue. </description>
<param-name>kaptcha.border.color</param-name>
<param-value>red</param-value>
</init-param>
<init-param>
<description>Thickness of the border around kaptcha. Legal values are > 0. </description>
<param-name>kaptcha.border.thickness</param-name>
<param-value>5</param-value>
</init-param>
<init-param>
<description>Width in pixels of the kaptcha image. </description>
<param-name>kaptcha.image.width</param-name>
<param-value>80</param-value>
</init-param>
<init-param>
<description>Height in pixels of the kaptcha image. </description>
<param-name>kaptcha.image.height</param-name>
<param-value>40</param-value>
</init-param>
<init-param>
<description>The image producer. </description>
<param-name>kaptcha.producer.impl</param-name>
<param-value>com.google.code.kaptcha.impl.DefaultKaptcha </param-value>
</init-param>
<init-param>
<description>The text producer. </description>
<param-name>kaptcha.textproducer.impl</param-name>
<param-value>com.google.code.kaptcha.text.impl.DefaultTextCreator</param-value>
</init-param>
<init-param>
<description>The characters that will create the kaptcha. </description>
<param-name>kaptcha.textproducer.char.string</param-name>
<param-value>abcde2345678gfynmnpwx </param-value>
</init-param>
<init-param>
<description>The number of characters to display. </description>
<param-name>kaptcha.textproducer.char.length</param-name>
<param-value>5</param-value>
</init-param>
<init-param>
<description>A list of comma separated font names.</description>
<param-name>kaptcha.textproducer.font.names</param-name>
<param-value>Arial, Courier</param-value>
</init-param>
<init-param>
<description>The size of the font to use. </description>
<param-name>kaptcha.textproducer.font.size</param-name>
<param-value>23</param-value>
</init-param>
<init-param>
<description>The color to use for the font. Legal values are r,g,b. </description>
<param-name>kaptcha.textproducer.font.color</param-name>
<param-value>black</param-value>
</init-param>
<init-param>
<description>The noise producer. </description>
<param-name>kaptcha.noise.impl</param-name>
<param-value>com.google.code.kaptcha.impl.NoNoise </param-value>
</init-param>
<init-param>
<description>The noise color. Legal values are r,g,b. </description>
<param-name>kaptcha.noise.color</param-name>
<param-value>black</param-value>
</init-param>
<init-param>
<description>The obscurificator implementation. </description>
<param-name>kaptcha.obscurificator.impl</param-name>
<param-value>com.google.code.kaptcha.impl.ShadowGimpy</param-value>
</init-param>
<init-param>
<description>The background implementation. </description>
<param-name>kaptcha.background.impl</param-name>
<param-value>com.google.code.kaptcha.impl.DefaultBackground</param-value>
</init-param>
<init-param>
<description>Ending background color. Legal values are r,g,b. </description>
<param-name>kaptcha.background.clear.to</param-name>
<param-value>white</param-value>
</init-param>
<init-param>
<description>The word renderer implementation. </description>
<param-name>kaptcha.word.impl</param-name>
<param-value>com.google.code.kaptcha.text.impl.DefaultWordRenderer</param-value>
</init-param>
<init-param>
<description>The value for the kaptcha is generated and is put into the HttpSession. This is the key value for that item in the session. </description>
<param-name>kaptcha.session.key</param-name>
<param-value>KAPTCHA_SESSION_KEY</param-value>
</init-param>
<init-param>
<description>The date the kaptcha is generated is put into the HttpSession. This is the key value for that item in the session. </description>
<param-name>kaptcha.session.date</param-name>
<param-value>KAPTCHA_SESSION_DATE</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/Kaptcha.jpg</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>KaptchaExample.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.编写KaptchaExample.jsp
这里用到了jQuery,所以添加了jQuery的库
[javascript] view plaincopy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Kaptcha Example</title>
<mce:script type="text/javascript" src="js/jquery-1.3.2.js" mce_src="js/jquery-1.3.2.js"></mce:script>
</head>
<body>
Enter in the
<a href="http://code.google.com/p/kaptcha/" mce_href="http://code.google.com/p/kaptcha/">Kaptcha</a> to see if it
matches what is stored in the session attributes.
<table>
<tr>
<td>
<img src="Kaptcha.jpg" mce_src="Kaptcha.jpg" id="kaptchaImage" />
<mce:script type="text/javascript"><!--
$('#kaptchaImage').click(
function() {
$(this).hide().attr('src',
'Kaptcha.jpg?' + Math.floor(Math.random() * 100)).fadeIn();
})
// --></mce:script>
<br />
单击换图片
</td>
<td valign="top">
<form method="POST">
<br>
验证码::
<input type="text" name="kaptchafield">
<br />
<input type="submit" name="submit">
</form>
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
<%
String c = (String) session
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String parm = (String) request.getParameter("kaptchafield");
System.out.println(c);
out.println("Parameter: " + parm + " ? Session Key: " + c + " : ");
if (c != null && parm != null)
{
if (c.equals(parm))
{
out.println("<b>true</b>");
} else
{
out.println("<b>false</b>");
}
}
%>
</body>
</html>
kaptcha是一个非常实用的验证码生成工具,有了它,你可以生成各种样式的验证码,因为它是可配置的。
kaptcha工作的原理是调用com.google.code.kaptcha.servlet.KaptchaServlet,生成一个图片。同时将生成的验证码字符串放到HttpSession中。
kaptcha可以配置一下信息:
验证码的字体
验证码字体的大小
验证码字体的字体颜色
验证码内容的范围(数字,字母,中文汉字!)
验证码图片的大小,边框,边框粗细,边框颜色
验证码的干扰线(可以自己继承com.google.code.kaptcha.NoiseProducer写一个自定义的干扰线)
验证码的样式(鱼眼样式、3D、普通模糊……当然也可以继承com.google.code.kaptcha.GimpyEngine自定义样式)
……
详细信息请看下面的web.xml文件
下面介绍一下用法:
1.首先去官网下载jar:http://code.google.com/p/kaptcha/
2.建立一个web项目,导入kaptcha-2.3.jar到环境变量中。
3.配置web.xml文件
其实就是配置com.google.code.kaptcha.servlet.KaptchaServlet
[xhtml] view plaincopy
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
<init-param>
<description> Border around kaptcha. Legal values are yes or no. </description>
<param-name>kaptcha.border</param-name>
<param-value>no</param-value>
</init-param>
<init-param>
<description>Color of the border. Legal values are r,g,b (and optional alpha) or white,black,blue. </description>
<param-name>kaptcha.border.color</param-name>
<param-value>red</param-value>
</init-param>
<init-param>
<description>Thickness of the border around kaptcha. Legal values are > 0. </description>
<param-name>kaptcha.border.thickness</param-name>
<param-value>5</param-value>
</init-param>
<init-param>
<description>Width in pixels of the kaptcha image. </description>
<param-name>kaptcha.image.width</param-name>
<param-value>80</param-value>
</init-param>
<init-param>
<description>Height in pixels of the kaptcha image. </description>
<param-name>kaptcha.image.height</param-name>
<param-value>40</param-value>
</init-param>
<init-param>
<description>The image producer. </description>
<param-name>kaptcha.producer.impl</param-name>
<param-value>com.google.code.kaptcha.impl.DefaultKaptcha </param-value>
</init-param>
<init-param>
<description>The text producer. </description>
<param-name>kaptcha.textproducer.impl</param-name>
<param-value>com.google.code.kaptcha.text.impl.DefaultTextCreator</param-value>
</init-param>
<init-param>
<description>The characters that will create the kaptcha. </description>
<param-name>kaptcha.textproducer.char.string</param-name>
<param-value>abcde2345678gfynmnpwx </param-value>
</init-param>
<init-param>
<description>The number of characters to display. </description>
<param-name>kaptcha.textproducer.char.length</param-name>
<param-value>5</param-value>
</init-param>
<init-param>
<description>A list of comma separated font names.</description>
<param-name>kaptcha.textproducer.font.names</param-name>
<param-value>Arial, Courier</param-value>
</init-param>
<init-param>
<description>The size of the font to use. </description>
<param-name>kaptcha.textproducer.font.size</param-name>
<param-value>23</param-value>
</init-param>
<init-param>
<description>The color to use for the font. Legal values are r,g,b. </description>
<param-name>kaptcha.textproducer.font.color</param-name>
<param-value>black</param-value>
</init-param>
<init-param>
<description>The noise producer. </description>
<param-name>kaptcha.noise.impl</param-name>
<param-value>com.google.code.kaptcha.impl.NoNoise </param-value>
</init-param>
<init-param>
<description>The noise color. Legal values are r,g,b. </description>
<param-name>kaptcha.noise.color</param-name>
<param-value>black</param-value>
</init-param>
<init-param>
<description>The obscurificator implementation. </description>
<param-name>kaptcha.obscurificator.impl</param-name>
<param-value>com.google.code.kaptcha.impl.ShadowGimpy</param-value>
</init-param>
<init-param>
<description>The background implementation. </description>
<param-name>kaptcha.background.impl</param-name>
<param-value>com.google.code.kaptcha.impl.DefaultBackground</param-value>
</init-param>
<init-param>
<description>Ending background color. Legal values are r,g,b. </description>
<param-name>kaptcha.background.clear.to</param-name>
<param-value>white</param-value>
</init-param>
<init-param>
<description>The word renderer implementation. </description>
<param-name>kaptcha.word.impl</param-name>
<param-value>com.google.code.kaptcha.text.impl.DefaultWordRenderer</param-value>
</init-param>
<init-param>
<description>The value for the kaptcha is generated and is put into the HttpSession. This is the key value for that item in the session. </description>
<param-name>kaptcha.session.key</param-name>
<param-value>KAPTCHA_SESSION_KEY</param-value>
</init-param>
<init-param>
<description>The date the kaptcha is generated is put into the HttpSession. This is the key value for that item in the session. </description>
<param-name>kaptcha.session.date</param-name>
<param-value>KAPTCHA_SESSION_DATE</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/Kaptcha.jpg</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>KaptchaExample.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.编写KaptchaExample.jsp
这里用到了jQuery,所以添加了jQuery的库
[javascript] view plaincopy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Kaptcha Example</title>
<mce:script type="text/javascript" src="js/jquery-1.3.2.js" mce_src="js/jquery-1.3.2.js"></mce:script>
</head>
<body>
Enter in the
<a href="http://code.google.com/p/kaptcha/" mce_href="http://code.google.com/p/kaptcha/">Kaptcha</a> to see if it
matches what is stored in the session attributes.
<table>
<tr>
<td>
<img src="Kaptcha.jpg" mce_src="Kaptcha.jpg" id="kaptchaImage" />
<mce:script type="text/javascript"><!--
$('#kaptchaImage').click(
function() {
$(this).hide().attr('src',
'Kaptcha.jpg?' + Math.floor(Math.random() * 100)).fadeIn();
})
// --></mce:script>
<br />
单击换图片
</td>
<td valign="top">
<form method="POST">
<br>
验证码::
<input type="text" name="kaptchafield">
<br />
<input type="submit" name="submit">
</form>
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
<%
String c = (String) session
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String parm = (String) request.getParameter("kaptchafield");
System.out.println(c);
out.println("Parameter: " + parm + " ? Session Key: " + c + " : ");
if (c != null && parm != null)
{
if (c.equals(parm))
{
out.println("<b>true</b>");
} else
{
out.println("<b>false</b>");
}
}
%>
</body>
</html>
相关推荐
简单轻巧的验证码生成工具类。
一个.net core,跨平台的图形验证码生成工具包,基于ImageSharp。
kaptcha-2.3.2.jar,一个java开源的验证码工具包,kaptcha是一个非常实用的验证码生成工具。有了它,你可以生成各种样式的验证码,因为它是可配置的,有需要的赶快下载吧!
一个php验证码生成工具,<img src="authCode.php">
这个是生成图片验证码的工具,可以直接使用的,使用教程在https://blog.csdn.net/qq_31844349/article/details/97185842,这个只适合学习使用,不能用在商业软件中,可能会存在BUG,所以不能使用在系统软件开发中,如果您...
vericode 验证码jar包, ValidateCode.jar CAPTCHAResult.java
随机生成验证码工具类 长度为4位或者6位
kaptcha是google开源的一个非常实用的验证码生成工具类,可以利用kaptcha生成各种各样的验证码,但是它没有上传到maven中央仓库。里面包含kaptcha jar包和打包命令
验证码生成工具类+验证码验证学习笔记 验证码生成工具类参考自:java图形验证码生成工具类及web页面校验验证码,万分感谢! 效果图: 代码如下: package com.my.demo.session.others; import javax.imageio....
好看的图片验证码,包含干扰线、噪点、扭曲图片等。。
随机生成验证码的工具类封装
Java验证码生成插件,插件内置4种样式,支持用户自定义扩展
自己做的关于验证码生成的工具 大家可以下载看看 能做出识别的来更好 呵呵……
captcha是一个图片验证码生成工具库,通过调用ImageCaptchaUtil中的方法来生成验证码图片信息,支持返回图片流,图片base64和图片base64Data。可设置干扰线类型来生成不同干扰类型的验证码图片。可已自定义图片背景...
主要为大家详细介绍了java图形验证码生成工具类,web页面校验验证码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下