首页 > 代码库 > jcaptcha sample 制作验证码
jcaptcha sample 制作验证码
Skip to end of metadata Created by marc antoine garrigue, last modified by Jeremy Waters on Feb 23, 2012Go to start of metadataDescriptionThis integration module provides the shortest way to integrate JCaptcha to your web application.This module is available since jcaptcha 2.0This integration module provides the new default captcha configuration :All you need to do is add the jcaptcha jar to your project, make a reference to the SimpleImageCaptchaServlet in your web.xml and then use the servlet session id to validate what the user submits on your form against the captcha service.Set up Add the jcaptcha jar file into the WEB-INF/lib directory of your .war file If your app or server do not already have commons-logging and commons-collection into the WEB-INF/lib directory of your .war 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>jcaptcha</servlet-name> <servlet-class>com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet</servlet-class></servlet><servlet-mapping> <servlet-name>jcaptcha</servlet-name> <url-pattern>/jcaptcha.jpg</url-pattern></servlet-mapping> Add the folowing image tag to the form you want to protect, this call will asks the SimpleImageCaptchaServlet to generate a fresh new captcha<form action="submit.action">... <img src="jcaptcha.jpg" /> <input type="text" name="jcaptcha" value="" />...</form> In your code that manages the submit action add the following code fragment to validate the user inputString userCaptchaResponse = request.getParameter("jcaptcha");boolean captchaPassed = SimpleImageCaptchaServlet.validateResponse(request, userCaptchaResponse);if(captchaPassed){// proceed to submit action}else{// return error to user}And that‘s it!Sample Web App see the attached sample web app (warning, this war contains commons-logging and commons-collections)Jcaptcha 2.0 jars jcaptcha-api-1.0.jar jcaptcha-2.0-alpha-1-SNAPSHOT.jar jcaptcha-integration-simple-servlet-2.0-alpha-1-SNAPSHOT.jar filters-2.0.235.jar
按照上面说的做,然后把相关的jar放进去,注意还有 commons-logging and commons-collection 这两个.
其他网友说很简单,但是第一次做也不觉的简单,做完了才觉得简单.这个是网上的教程,由于我这里的网络不好所以就记录下来,和spring整合也可以这样做,先简单的整合起来,后面再优化
教程原网址 jcaptcha
说一个可疑的bug
当注册的时候出现用户名重复的问题之后,修改用户名,此时会报验证码错误,仔细看看验证码没有错啊,但是程序却提示错了,这个类似的问题我遇到了,当用这个插件时,如果后台出现验证失败,而且验证码(猜测是放在第一个验证的)已经被验证码,那么就不能被第二次验证,我本地的后台时报了异常的.所以在每次经过后台验证出错之后都要刷新验证码,就是在ajax的success方法中加入刷新页面的js 方法.
jcaptcha sample 制作验证码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。