Lots of guys asked me help in integrating a simple jCaptcha module to their struts application.Was a bit busy with my work so am making this entry late. hope this is helpful
JCaptcha stands for Java Completely Automated Public Test to tell Computers and Humans Apart. Four years since the inception, the 1.0 release is the first declared as stable, available on the central Maven repository or on Sourceforge. The 1.0 release keep the JDK3 backward compatibility, next one 2.0-alpha1 will be built with JDK6 and provide compatibility with JDK5. The JCaptcha project is designed to ease extension, integration and configuration.
jCaptcha has the objective of checking the authenticity of the user trying to perform some action on the page. It allows providing a check on the page by verifying the user’s value with the image value generated to access the functionality of user. It can be used to determine the validity of registration in a page.
The user should be using java version 1.6 or higher.
The jar files required are:
JCaptcha tries to strictly respect the Inversion of Control pattern, to ease creation of components for concrete applications. An application using JCaptcha should only manipulate a CaptchaService instance.
For maven users the simple procedure is to include the specific jar dependency to the pom.xml file instance as follows:
For those who don’t use maven the simple procedure is to add the jcaptcha-all.jar and commons-collection-3.2 or greater to the application class path, ie in the WEB-INF/lib folder.
Provide the reference of the new servlet in the web.xml file to instantiate and allow access to the servlet as:
Add an image tag to the form you want to protect, by referring to the servlet call which asks the SimpleImageCaptchaServlet to generate a fresh new captcha.
<img src="jcaptcha.jpg" /> <input type="text" name="jcaptcha" value="" />
In the action file that validates the previous form’s action validate the input of the user with respect to the captcha value.
String userCaptchaResponse =request.getParameter ("jcaptcha");
boolean captchaPassed = SimpleImageCaptchaServlet.validateResponse(request,userCaptchaResponse);
// proceed to submit action
// return error to user