BotDetect Java CAPTCHA Generator

CAPTCHA Generator Features:

Quickstarts:

BotDetect Java Captcha generator allows you to easily add Captcha protection to various types of Java based web forms.

We'll use default BotDetect settings in all code snippets.

To see how powerful and customizable BotDetect is, check the BotDetect features demo.

1. Show a Captcha Challenge on the JSF Form

BotDetect Java Captcha provides a dedicated JavaServer Faces tag 'jsfCaptcha'.

'jsfCaptcha' integration steps depend on whether you use standard JSF (.jsp) or Facelets (.xhtml) view handler(s).

Standard JSF

  • declare taglib at the begining of the .jsp file:
  • <%@taglib prefix="botDetect" uri="https://captcha.com/java/jsf"%>
    
  • add (optionaly) attribute prependId="false" to <h:form> opening tag
  • within the <form> insert:
  • <h:outputLabel for="captchaCode" 
      value="Retype the characters from the picture:"/>
      
    <botDetect:jsfCaptcha id="exampleCaptcha" 
                          binding="#{captchaExampleBean.captcha}"/>
                          
    <h:inputText id="captchaCode" value="#{captchaExampleBean.captchaCode}"/>
    

When you open your form in a browser, the markup given above should render similar as:

BotDetect CAPTCHA added to an JSP page

In order to later perform CAPTCHA validation jsfCaptcha tag must be bound with the corresponding property of the backing bean. This backing bean property should be of the JsfCaptcha type, and include both getter and setter access:

import botdetect.web.jsf.JsfCaptcha;
  [...]

private JsfCaptcha captcha;
  [...]

public JsfCaptcha getCaptcha() {
   return captcha;
}

public void setCaptcha(JsfCaptcha captcha) {
   this.captcha = captcha;
}

2. Validate User's Captcha Input During Form Submission

On form submit, the Captcha validation result must be checked:

boolean isHuman = captcha.validate(captchaCode);
if (isHuman) {
  correctLabelVisible = true;
  incorrectLabelVisible = false;
} else {
  correctLabelVisible = false;
  incorrectLabelVisible = true;
}

3. Add BotDetect Java CAPTCHA Library Dependency

Here is how to add BotDetect Java CAPTCHA Library dependency in various dependency management scenarios:

To manually add BotDetect Captcha library to classpath, copy the following four jar files from BotDetect Java download package to application's WEB-INF/lib folder:

  • botdetect-4.0.beta1.jar
  • botdetect-servlet-4.0.beta1.jar
  • botdetect-jsp20-4.0.beta1.jar
  • botdetect-jsf20-4.0.beta1.jar

In case your application uses JSF 1.2 you will need to copy the botdetect-jsf12-4.0.beta1.jar file instead of botdetect-jsf20-4.0.beta1.jar file.

To share BotDetect Captcha among multiple applications, these BotDetect jar files above should be copied into 'lib' directory of web container or application server's domain.

4. Register BotDetect Captcha Servlet

Update your application configuration (web.xml) file.

<servlet>
  <servlet-name>BotDetect Captcha</servlet-name>
  <servlet-class>com.captcha.botdetect.web.servlet.CaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>BotDetect Captcha</servlet-name>
  <url-pattern>/botdetectcaptcha</url-pattern>
</servlet-mapping>

BotDetect Java CAPTCHA Free version

You can download BotDetect Java CAPTCHA library for free and use it immediately! Your forms can be protected from spam (and bots in general) in minutes.

Keep in mind that we offer basic email support for free to all BotDetect users. So if you need any assistance integrating BotDetect or have any questions or feedback, our Support department is at your disposal.

Once the BotDetect Captcha generator library has been integrated into your Java web application and you're satisfied with how it works, it's easy to upgrade your license if you need the extra features and options offered by commercial BotDetect versions.

BotDetect Java Captcha Free Download

BotDetect Java CAPTCHA System Requirements

OSApplication ServerJava

Supported Operating Systems:

  • Linux
  • Windows

Supported servers:

  • Apache Tomcat 5+
  • JBoss/WildFly 4+
  • WebSphere 6+
  • WebLogic 9+
  • GlassFish 2+
  • Resin 3+
  • Jetty 5+

Java/Servlet/JSP/JSF:

  • Java 5+
  • Java Servlet 2.3+
  • JavaServer Pages 2.0+
  • JavaServer Faces 1.2+

Please Note

BotDetect Java Captcha Library v4.0.Beta1 is an in-progress port of BotDetect 4 Captcha, and we need you to guide our efforts towards a polished product. Please let us know if you encounter any bugs, implementation issues, or a usage scenario you would like to discuss.