- 浏览: 588947 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
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 793prototype 是在 IE 4 及其以后版本引入的一个针对 ... -
JSP EL表达式和JSP脚本<%%> 无法在外部引用的JS文件中执行
2012-02-09 16:24 1690转自http://www.blogjava.net/algz/ ... -
关于el表达式的隐含对象
2011-12-27 23:21 10791.${param.action}其中param为el表达式隐 ... -
<c:choose>标签的用法
2011-12-26 23:01 1235<c:choose> <c:when te ... -
js解析json和xml
2011-12-24 22:34 1537转自http://www.cnblogs.com/lu ... -
关于ie与firefox css兼容性的文章
2011-09-28 13:31 1003一、IE与FireFox的js和css png透明 Alph ... -
关于ie与firefox js兼容性的文章
2011-09-28 12:01 824最近作浏览器兼容性方面的工作,发现此篇文章,太好了,转帖收藏了 ... -
c标签报错,提示不接受任何表达式
2011-09-23 14:42 1027异常提示,说不接受任何表达式,后来在网上找到一个解决方案,说是 ... -
jquery城市联动
2011-08-29 14:34 1138转载自 http://dcxy134-126-com.itey ... -
如何获得request中所有的参数名和参数值
2011-08-24 12:47 1514转自http://blog.csdn.net/yizdream ... -
ie6下js window.location.href无法正常跳转
2011-07-25 11:09 2021问题: ie6中使用window.location.hr ... -
jsp页面格式化数字或时间
2011-06-10 18:13 94350转载自:http://blog.csdn.net/hakuna ... -
带checkbox的树形菜单
2011-04-01 15:49 6050dtree_checkbox.js 1.判断并选中check ... -
一个有用的时间控件
2010-12-03 14:20 922WdatePicker.js -
firefox调用本地资源
2010-12-02 12:33 1636调用firefox原理是利用xpcom组件实现,具体方式如下 ... -
js 动态改变div的定位 firefox与ie差别
2010-06-23 15:40 1635document.getElementById("_ ... -
树结构备份
2010-06-11 09:32 917//为每个树枝创建叶子结点 private ... -
ie dom 查看器
2010-05-25 13:28 1072ie web developer v5 插件官网: http ... -
如何获得父窗口对象
2010-04-12 13:19 1192现有一个main.jsp 页面中是一个frameset 框架 ... -
js判断浏览器类型以及版本
2010-01-18 17:38 4763原创:李战(leadzen) 阿里软件 2008-9-6 杭州 ...
相关推荐
验证码 kaptcha之springboot用法.docx验证码 kaptcha之springboot用法.docx
JavaWeb开发可以拿来看看,了解一下谷歌验证码的使用
在一个web应用中验证码是一个常见的元素。不管是防止机器人还是爬虫都有一定的作用,下面这篇文章主要给大家介绍了登陆验证码kaptcha结合spring boot用法的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧。
实现spring-gateway登录验证码校验,使用randomstr参数作为每次生成验证码图片的唯一标识,验证码Kaptcha插件
这是个 自己写的 可以改样式 的非常漂亮 美观的验证码
谷歌的验证码生成工具包,下载解压,使用命令mvn install:install-file -Dfile=(你的路径)/kaptcha-2.3.2.jar -DgroupId=com.google.code.kaptcha -DartifactId=kaptcha -Dversion=2.3.2 -Dpackaging=jar安装到...
Java使用kaptcha实现验证码功能必备jar包,使用简单,web.xml中配置即用。 Java使用kaptcha实现验证码功能必备jar包,使用简单,web.xml中配置即用。
此压缩包主要是用来实现验证码功能的,包括谷歌验证码kaptcha-2.3.2.jar包和一些配置说明文档
谷歌验证码使用工具——kaptcha-2.3.2的使用非常简单;
kaptcha 图片验证码 springMVC project demo
vue+springboot+redis+kaptcha实现登录页验证码
kaptcha demo 简单的验证码工具 kaptcha demo 简单的验证码工具
google的Kaptcha生成验证码,附件有jar资源和使用Demo 一款可以各种配置显示方式的验证码
主要介绍了spring整合kaptcha验证码的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
kaptcha验证码配置的3种方式 参照本演示项目
Google验证码插件jar包,直接解压存入本地仓库即可使用
google kaptcha-2.3.2.jar验证码的jar包,google把生成验证码的操作基本的封装好了,使用起来很方便。
kaptcha验证码生成jar包后台配置源代码 kaptcha生成验证码的作用:进行人机校验--防止机器脚本自动大量注册用户。 1、Kaptcha是谷歌开源的可高度配置的实用验证码生成工具。 2、过Kaptcha可阻拦大多数机器人脚本...
java的验证码生成工具,kaptcha2.3.2验证码jar包。
自己实现用idea实现了下google的kaptcha验证码,挺好用的,使用简单方便,希望能够帮助到大家