- 浏览: 601805 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
Garlic_90:
ireport分页的话代码写起来有些复杂,我以前试过,比较简单 ...
ireport分页显示 -
feijiing:
nice,problem solved,thanks!
虚拟机安装centos no valid devices were found on which to cereate new file systems -
Jocken:
引用的jar包需要怎么加在命令里面?十多个呢,为什么配在MAN ...
linux 如何运行jar包 -
xiaoqiao800:
看到你的问题,有帮助,我之前都是手动的clear项目下的cla ...
The project cannot be built until build path errors are resolved -
mfkdzhou:
楼主好,我现在也遇到这个问题,可以把源代码发一份不?谢谢了。8 ...
java打印
以下内容摘自:http://code.google.com/p/kaptcha/wiki/HowToUse
Basic use of kaptcha in your webapp is quite easy. All you need to do is add the jar to your project, make a reference to the kaptcha servlet in your web.xml and then check the servlet session for the generated kaptcha value and compare it to what the user submits on your form.
For those of you looking for an audio kaptcha solution, this product probably won't ever support that unless someone else wants to work on it. Sorry.
Note: If you are currently using JCaptcha in the same .war file as Kaptcha, you will have a conflict with the image generation library. You must remove JCaptcha. See this issue for details.
Example
Included in the distribution is an example .war file for you to play with. Note that this .war file will only work with Java 1.5 and higher. For easiest setup, download Tomcat. I use 5.5.x and I download the 'Core' distribution.
Then, copy the kaptcha.war file into the webapps directory. Make sure it is named 'kaptcha.war'. Then, start up Tomcat. I type on Unix: ./bin/catalina.sh run or on Windows: bin/catalina.bat run.
Now, visit: http://localhost:8080/kaptcha/KaptchaExample.jsp
If you edit the web.xml file in the exploded kaptcha.war folder you can test changes to the ConfigParameters quite easily.
Details
Here are the details of how to integrate Kaptcha into your own application.
Put the appropriate .jar file (depending on which JDK you are using) into the WEB-INF/lib directory of your .war file.
Put the image tag into your page (checking that the path to the .jpg matches up with what is defined in your web.xml below for the url-pattern):
<form action="submit.action">
<img src="kaptcha.jpg" /> <input type="text" name="kaptcha" value="" />
</form>
Put the reference in your web.xml (checking that the url-pattern path matches up with what you put in your html fragment above):
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/kaptcha.jpg</url-pattern>
</servlet-mapping>
In your code that manages the submit action:
String kaptchaExpected = (String)request.getSession()
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String kaptchaReceived = request.getParameter("kaptcha");
if (kaptchaReceived == null || !kaptchaReceived.equalsIgnoreCase(kaptchaExpected))
{
setError("kaptcha", "Invalid validation code.");
}
Make sure to start your JDK with -Djava.awt.headless=true
That is it!
Extra
If you love JQuery like I do, you can use it to easily solve the problem that happens when someone can't read the image that was generated for them. What this does is bind a function to the onclick handler for the img element so that when the image is clicked on, it will get reloaded. Note the use of the query string to append a random number to the end. This is because the browser has already cached the image and the query string makes it look like a new request.
<img src="/kaptcha" width="200" id="kaptchaImage" />
<script type="text/javascript">
$(function(){
$('#kaptchaImage').click(function () { $(this).attr('src', '/kaptcha.jpg?' + Math.floor(Math.random()*100) ); })
});
</script>
<br /><small>Can't read the image? Click it to get a new one.</small>
If you want to get fancy, you can add an extra visual effect when refreshing the image. This example uses the fadeIn() effect when you click on it:
$('#kaptchaImage').click(function () {
$(this).hide()
.attr('src', '/kaptcha.jpg?' + Math.floor(Math.random()*100) )
.fadeIn();
})
关于验证码的扩展配置:
Configuration is done through web.xml. All values can be left blank and a default value will be chosen.
Below is an example of the init-param you would add to your web.xml. If you want to set other variables, then you would add more init-param blocks.
<init-param>
<param-name>kaptcha.border</param-name>
<param-value>yes</param-value>
</init-param>
Note: This only works with the KaptchaServlet. SimpleServlet does not pay attention to the web.xml parameters.
Details
These values are stored in the com.google.code.kaptcha.Constants class.
Constant Description Default
kaptcha.border Border around kaptcha. Legal values are yes or no. yes
kaptcha.border.color Color of the border. Legal values are r,g,b (and optional alpha) or white,black,blue. black
kaptcha.border.thickness Thickness of the border around kaptcha. Legal values are > 0. 1
kaptcha.image.width Width in pixels of the kaptcha image. 200
kaptcha.image.height Height in pixels of the kaptcha image. 50
kaptcha.producer.impl The image producer. com.google.code.kaptcha.impl.DefaultKaptcha
kaptcha.textproducer.impl The text producer. com.google.code.kaptcha.text.impl.DefaultTextCreator
kaptcha.textproducer.char.string The characters that will create the kaptcha. abcde2345678gfynmnpwx
kaptcha.textproducer.char.length The number of characters to display. 5
kaptcha.textproducer.font.names A list of comma separated font names. Arial, Courier
kaptcha.textproducer.font.size The size of the font to use. 40px.
kaptcha.textproducer.font.color The color to use for the font. Legal values are r,g,b. black
kaptcha.textproducer.char.space The space between the characters 2
kaptcha.noise.impl The noise producer. com.google.code.kaptcha.impl.DefaultNoise
kaptcha.noise.color The noise color. Legal values are r,g,b. black
kaptcha.obscurificator.impl The obscurificator implementation. com.google.code.kaptcha.impl.WaterRipple
kaptcha.background.impl The background implementation. com.google.code.kaptcha.impl.DefaultBackground
kaptcha.background.clear.from Starting background color. Legal values are r,g,b. light grey
kaptcha.background.clear.to Ending background color. Legal values are r,g,b. white
kaptcha.word.impl The word renderer implementation. com.google.code.kaptcha.text.impl.DefaultWordRenderer
kaptcha.session.key The value for the kaptcha is generated and is put into the HttpSession. This is the key value for that item in the session. KAPTCHA_SESSION_KEY
kaptcha.session.date The date the kaptcha is generated is put into the HttpSession. This is the key value for that item in the session. KAPTCHA_SESSION_DATE
Basic use of kaptcha in your webapp is quite easy. All you need to do is add the jar to your project, make a reference to the kaptcha servlet in your web.xml and then check the servlet session for the generated kaptcha value and compare it to what the user submits on your form.
For those of you looking for an audio kaptcha solution, this product probably won't ever support that unless someone else wants to work on it. Sorry.
Note: If you are currently using JCaptcha in the same .war file as Kaptcha, you will have a conflict with the image generation library. You must remove JCaptcha. See this issue for details.
Example
Included in the distribution is an example .war file for you to play with. Note that this .war file will only work with Java 1.5 and higher. For easiest setup, download Tomcat. I use 5.5.x and I download the 'Core' distribution.
Then, copy the kaptcha.war file into the webapps directory. Make sure it is named 'kaptcha.war'. Then, start up Tomcat. I type on Unix: ./bin/catalina.sh run or on Windows: bin/catalina.bat run.
Now, visit: http://localhost:8080/kaptcha/KaptchaExample.jsp
If you edit the web.xml file in the exploded kaptcha.war folder you can test changes to the ConfigParameters quite easily.
Details
Here are the details of how to integrate Kaptcha into your own application.
Put the appropriate .jar file (depending on which JDK you are using) into the WEB-INF/lib directory of your .war file.
Put the image tag into your page (checking that the path to the .jpg matches up with what is defined in your web.xml below for the url-pattern):
<form action="submit.action">
<img src="kaptcha.jpg" /> <input type="text" name="kaptcha" value="" />
</form>
Put the reference in your web.xml (checking that the url-pattern path matches up with what you put in your html fragment above):
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/kaptcha.jpg</url-pattern>
</servlet-mapping>
In your code that manages the submit action:
String kaptchaExpected = (String)request.getSession()
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String kaptchaReceived = request.getParameter("kaptcha");
if (kaptchaReceived == null || !kaptchaReceived.equalsIgnoreCase(kaptchaExpected))
{
setError("kaptcha", "Invalid validation code.");
}
Make sure to start your JDK with -Djava.awt.headless=true
That is it!
Extra
If you love JQuery like I do, you can use it to easily solve the problem that happens when someone can't read the image that was generated for them. What this does is bind a function to the onclick handler for the img element so that when the image is clicked on, it will get reloaded. Note the use of the query string to append a random number to the end. This is because the browser has already cached the image and the query string makes it look like a new request.
<img src="/kaptcha" width="200" id="kaptchaImage" />
<script type="text/javascript">
$(function(){
$('#kaptchaImage').click(function () { $(this).attr('src', '/kaptcha.jpg?' + Math.floor(Math.random()*100) ); })
});
</script>
<br /><small>Can't read the image? Click it to get a new one.</small>
If you want to get fancy, you can add an extra visual effect when refreshing the image. This example uses the fadeIn() effect when you click on it:
$('#kaptchaImage').click(function () {
$(this).hide()
.attr('src', '/kaptcha.jpg?' + Math.floor(Math.random()*100) )
.fadeIn();
})
关于验证码的扩展配置:
Configuration is done through web.xml. All values can be left blank and a default value will be chosen.
Below is an example of the init-param you would add to your web.xml. If you want to set other variables, then you would add more init-param blocks.
<init-param>
<param-name>kaptcha.border</param-name>
<param-value>yes</param-value>
</init-param>
Note: This only works with the KaptchaServlet. SimpleServlet does not pay attention to the web.xml parameters.
Details
These values are stored in the com.google.code.kaptcha.Constants class.
Constant Description Default
kaptcha.border Border around kaptcha. Legal values are yes or no. yes
kaptcha.border.color Color of the border. Legal values are r,g,b (and optional alpha) or white,black,blue. black
kaptcha.border.thickness Thickness of the border around kaptcha. Legal values are > 0. 1
kaptcha.image.width Width in pixels of the kaptcha image. 200
kaptcha.image.height Height in pixels of the kaptcha image. 50
kaptcha.producer.impl The image producer. com.google.code.kaptcha.impl.DefaultKaptcha
kaptcha.textproducer.impl The text producer. com.google.code.kaptcha.text.impl.DefaultTextCreator
kaptcha.textproducer.char.string The characters that will create the kaptcha. abcde2345678gfynmnpwx
kaptcha.textproducer.char.length The number of characters to display. 5
kaptcha.textproducer.font.names A list of comma separated font names. Arial, Courier
kaptcha.textproducer.font.size The size of the font to use. 40px.
kaptcha.textproducer.font.color The color to use for the font. Legal values are r,g,b. black
kaptcha.textproducer.char.space The space between the characters 2
kaptcha.noise.impl The noise producer. com.google.code.kaptcha.impl.DefaultNoise
kaptcha.noise.color The noise color. Legal values are r,g,b. black
kaptcha.obscurificator.impl The obscurificator implementation. com.google.code.kaptcha.impl.WaterRipple
kaptcha.background.impl The background implementation. com.google.code.kaptcha.impl.DefaultBackground
kaptcha.background.clear.from Starting background color. Legal values are r,g,b. light grey
kaptcha.background.clear.to Ending background color. Legal values are r,g,b. white
kaptcha.word.impl The word renderer implementation. com.google.code.kaptcha.text.impl.DefaultWordRenderer
kaptcha.session.key The value for the kaptcha is generated and is put into the HttpSession. This is the key value for that item in the session. KAPTCHA_SESSION_KEY
kaptcha.session.date The date the kaptcha is generated is put into the HttpSession. This is the key value for that item in the session. KAPTCHA_SESSION_DATE
发表评论
-
关于prototype介绍
2012-02-25 15:21 819prototype 是在 IE 4 及其以后版本引入的一个针对 ... -
JSP EL表达式和JSP脚本<%%> 无法在外部引用的JS文件中执行
2012-02-09 16:24 1758转自http://www.blogjava.net/algz/ ... -
关于el表达式的隐含对象
2011-12-27 23:21 11211.${param.action}其中param为el表达式隐 ... -
<c:choose>标签的用法
2011-12-26 23:01 1314<c:choose> <c:when te ... -
js解析json和xml
2011-12-24 22:34 1574转自http://www.cnblogs.com/lu ... -
关于ie与firefox css兼容性的文章
2011-09-28 13:31 1067一、IE与FireFox的js和css png透明 Alph ... -
关于ie与firefox js兼容性的文章
2011-09-28 12:01 875最近作浏览器兼容性方面的工作,发现此篇文章,太好了,转帖收藏了 ... -
c标签报错,提示不接受任何表达式
2011-09-23 14:42 1079异常提示,说不接受任何表达式,后来在网上找到一个解决方案,说是 ... -
jquery城市联动
2011-08-29 14:34 1191转载自 http://dcxy134-126-com.itey ... -
如何获得request中所有的参数名和参数值
2011-08-24 12:47 1550转自http://blog.csdn.net/yizdream ... -
ie6下js window.location.href无法正常跳转
2011-07-25 11:09 2054问题: ie6中使用window.location.hr ... -
jsp页面格式化数字或时间
2011-06-10 18:13 94422转载自:http://blog.csdn.net/hakuna ... -
带checkbox的树形菜单
2011-04-01 15:49 6085dtree_checkbox.js 1.判断并选中check ... -
一个有用的时间控件
2010-12-03 14:20 976WdatePicker.js -
firefox调用本地资源
2010-12-02 12:33 1684调用firefox原理是利用xpcom组件实现,具体方式如下 ... -
js 动态改变div的定位 firefox与ie差别
2010-06-23 15:40 1672document.getElementById("_ ... -
树结构备份
2010-06-11 09:32 944//为每个树枝创建叶子结点 private ... -
ie dom 查看器
2010-05-25 13:28 1128ie web developer v5 插件官网: http ... -
如何获得父窗口对象
2010-04-12 13:19 1242现有一个main.jsp 页面中是一个frameset 框架 ... -
js判断浏览器类型以及版本
2010-01-18 17:38 4799原创:李战(leadzen) 阿里软件 2008-9-6 杭州 ...
相关推荐
谷歌验证码(Google reCAPTCHA)是一种广泛用于防止网络爬虫和自动机器人滥用的验证机制,而Kaptcha则是Java实现的一个开源验证码生成库,它能够帮助开发者在自己的应用程序中轻松集成自定义的验证码功能,尤其适合...
Google的Kaptcha是一个流行的验证码生成库,它提供了多种配置选项来生成高质量的图像验证码。在Spring Boot这样的轻量级框架中集成Kaptcha可以简化开发过程,提高应用程序的安全性。 首先,我们需要在项目中引入...
在本文中,我们将深入探讨如何将登陆验证码kaptcha与Spring Boot整合,以便在Web应用程序中增强安全性。验证码在防止自动脚本、机器人和恶意爬虫的活动中起着至关重要的作用。Spring Boot以其轻量级、独立的特点,...
在本文中,我们将深入探讨如何将Kaptcha与Spring Boot整合以实现图形验证码的功能。Kaptcha是一个开源项目,用于生成各种类型的验证码,以防止自动化程序(如机器人)进行恶意操作。而Spring Boot是Java开发中的一个...
这是个 自己写的 可以改样式 的非常漂亮 美观的验证码
【谷歌验证码使用工具——kaptcha-2.3.2】是一款基于Java的开源验证码生成库,主要用于网站的身份验证,防止自动化的机器人或者恶意攻击者进行非法操作。kaptcha这个名字是"CAPTCHA"(Completely Automated Public ...
在Java Web开发中,`Kaptcha`是一个非常流行的开源库,用于生成这种安全的随机验证码。`Kaptcha`框架简化了在Java应用中集成验证码的过程,尤其适用于防止自动注册、垃圾邮件发送等场景。 `Kaptcha`框架的核心特性...
-- 登录验证码Kaptcha配置 --> <servlet-name>Kaptcha <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class> <!-- 配置Kaptcha生成器 --> <param-name>kaptcha.producer.impl ...
谷歌Kaptcha验证码jar包是Google提供的一种用于网页安全验证的工具。Kaptcha,源自马来语“cap”,意为“图片”,是一种开源项目,主要用于生成难以被机器识别的图像验证码,以此来防止自动化程序(如机器人)对网站...
本教程将介绍如何结合Vue.js前端框架、Spring Boot后端框架、Redis缓存服务以及Kaptcha验证码技术,实现一个前后端分离的登录页面验证码功能。这个组合可以提供高效、安全且用户友好的验证机制。 首先,Vue.js是一...
【kaptcha验证码小程序】 验证码(CAPTCHA)是一种用于验证用户是否为人类的自动化测试,它在互联网上广泛应用于注册、登录、评论等场景,防止恶意的自动机器人进行操作。kaptcha是一个开源的Java验证码生成库,它...
谷歌的验证码生成工具包,下载解压,使用命令mvn install:install-file -Dfile=(你的路径)/kaptcha-2.3.2.jar -DgroupId=com.google.code.kaptcha -DartifactId=kaptcha -Dversion=2.3.2 -Dpackaging=jar安装到...
《kaptcha验证码:Java平台上的高效解决方案》 验证码(CAPTCHA)作为一种防止自动化程序自动提交表单的安全机制,被广泛应用于网站登录、注册、评论等场景。在Java开发环境中,kaptcha是一个备受青睐的第三方插件...
《深入理解Kaptcha图片验证码在SpringMVC项目中的应用》 验证码作为一种常见的安全机制,用于防止恶意自动程序(如机器人)对网站进行非法操作,如批量注册、恶意投票等。Kaptcha是Google开源的一个用于生成图片...
本文将介绍spring整合kaptcha验证码的实现,主要通过讲解kaptcha的简介、开发工具及使用的核心技术、kaptcha两种使用方式、搭骨架、完善配置文件等几个方面,对spring整合kaptcha验证码的实现进行了详细的介绍。...
【kaptcha-2.3.2-google验证码插件】是一个基于Java开发的验证码生成插件,主要用于网站的安全验证,防止恶意自动程序(如机器人)进行非法操作,如批量注册、频繁提交表单等。该插件是Google开发的,因此在安全性和...
谷歌的Kaptcha是一款广泛应用于网站安全验证的开源项目,它为用户提供了一种高效且可定制的验证码生成器。验证码的主要目的是防止自动化的机器人或者恶意软件进行非法操作,例如批量注册、垃圾评论等。Kaptcha因其...
在本案例中,我们将探讨如何使用`Kaptcha`插件来生成动态验证码。`Kaptcha`是一个开源Java库,专为生成验证码图像而设计,具有高度可配置性,可以轻松集成到Web应用中。 首先,我们需要了解`Kaptcha`插件的基本用法...
Kaptcha是Google开发的一个开源Java库,专门用于生成复杂的图像验证码。这个库允许开发者自定义各种参数以适应不同网站的需求,而且提供了属性配置的方式,使得定制过程更为简便。 Kaptcha验证码实现的核心在于其...
Kaptcha是一个Java实现的开源验证码生成库,它允许开发者轻松地在Web应用中集成自定义的验证码功能。Kaptcha以其简单易用和高度可配置性而受到开发者欢迎。 Kaptcha库的核心概念是生成具有一定的模糊性和噪声的图像...