BotDetect CAPTCHA Java Code Examples

The BotDetect Java Captcha package includes a number of code examples which can help you get started with integrating BotDetect in your Java websites and configuring various Captcha options.

First Time Here?

Check the BotDetect Developer Crash Course for key integration steps.

Table of Contents

BotDetect PHP CAPTCHA Code Examples Location

After unpacking the BotDetect Captcha library, you can find the Java Captcha examples as .war files in the examples folder. Deploy these examples to your webserver(the webapps folder in Apache Tomcat installations, or in the /autodeploy subfolder of GlassFish's domain folder, etc.) and point your browser to BotDetect Captcha index page (e.g. http://localhost:8080/bdc4-captcha-index), which will guide you to individual examples.

BotDetect CAPTCHA JSP Integration Code Examples

Integration code examples show how to integrate BotDetect in your JSP websites.


Java JSP Basic Captcha Code Example

This code example shows the most basic source code required to protect a JSP form with BotDetect Captcha and validate the user input.

It can be used as a starting point when you are first learning how to use BotDetect.

Default Source Code File Online Source
examples/bdc4-jsp-basic-captcha-example.war

Java JSP Captcha Tag Code Example

This code example shows the most basic source code required to protect a JavaServer Pages form with BotDetect CAPTCHA's custom tag and validate the user input.

It can be used as a starting point when you are first learning how to use BotDetect.

Default Source Code File Online Source
examples/bdc4-jsp-captcha-tag-example.war

Java JSP Form Captcha Code Example

This code example shows how to add BotDetect Captcha protection to a typical JSP form.

Captcha validation is integrated with other form fields validation, and only submissions that meet all validation criteria are accepted.

This kind of validation could be used on various types of public forms which accept messages, and are at risk of unwanted automated submissions.

For example, it could be used to ensure bots can't submit anything to a contact form, add guestbook entries, blog post comments or anonymous message board / forum replies.

Default Source Code File Online Source
examples/bdc4-jsp-form-captcha-example.war

Java JSP Login Form Captcha Code Example

This code example shows how to add BotDetect Captcha validation to simple JSP login forms.

To prevent bots from trying to guess the login info by brute force submission of a large number of common values, the visitor first has to prove they are human (by solving the Captcha), and only then is their username and password submission checked against the authentication data store.

Also, if they enter an invalid username + password combination three times, they have to solve the Captcha again. This prevents attempts in which the attacker would first solve the Captcha themselves, and then let a bot brute-force the authentication info.

Default Source Code File Online Source
examples/bdc4-jsp-login-form-captcha-example.war

Java JSP jQuery Validation Captcha Code Example

This code example shows how to integrate BotDetect Captcha validation with jQuery Validation client-side form validation.

Client-side validation is not secure by itself (it can be bypassed trivially by bots that don't execute JavaScript at all), so the example shows how the protected form action must always be secured by server-side Captcha validation first, and uses client-side validation only to improve the user experience.

Default Source Code File Online Source
examples/bdc4-jsp-jquery-validation-captcha-example.war

BotDetect CAPTCHA JSF Integration Code Examples

Integration code examples show how to integrate BotDetect in your JSF websites.


Java JSF Basic Captcha Code Example

This code example shows the most basic source code required to protect a JavaServer Faces form with BotDetect CAPTCHA and validate the user input.

It can be used as a starting point when you are first learning how to use BotDetect.

Default Source Code File Online Source
examples/bdc4-jsf20-basic-captcha-example.war
examples/bdc4-jsf12-basic-captcha-example.war

Java JSF Facelets Code Example

This code example shows how to protect a JavaServer Faces form with Facelets presentation technology using BotDetect CAPTCHA and validate the user input.

Default Source Code File Online Source
examples/bdc4-jsf20-facelets-captcha-example.war
examples/bdc4-jsf12-facelets-captcha-example.war

Java JSF Login Form Captcha Code Example

This code example shows how to add BotDetect CAPTCHA protection to a typical JavaServer Faces login form.

To prevent bots from trying to guess the login info by brute force submission of a large number of common values, the visitor first has to prove they are human (by solving the CAPTCHA), and only then is their username and password submission checked against the authentication data store.

Also, if they enter an invalid username + password combination three times, they have to solve the CAPTCHA again. This prevents attempts in which the attacker would first solve the CAPTCHA themselves, and then let a bot brute-force the authentication info.

Default Source Code File Online Source
examples/bdc4-jsf20-login-form-captcha-example.war
examples/bdc4-jsf12-login-form-captcha-example.war

Java JSF Login Form Filter Captcha Code Example

The JSF Login Form Filter Captcha code example shows how to add BotDetect CAPTCHA validation to basic Login form filter in JavaServer Faces Web Applications.

To prevent bots from trying to guess the login info by brute force submission of a large number of common values, the visitor first has to prove they are human (by solving the CAPTCHA), and only then is their username and password submission checked against the authentication data store.

Also, if they enter an invalid username + password combination three times, they have to solve the CAPTCHA again. This prevents attempts in which the attacker would first solve the CAPTCHA themselves, and then let a bot brute-force the authentication info.

Default Source Code File Online Source
examples/bdc4-jsf20-login-form-filter-captcha-example.war
examples/bdc4-jsf12-login-form-filter-captcha-example.war

Java JSF Validator CAPTCHA Code Example

The JSF Validator Captcha code example shows how to integrate BotDetect CAPTCHA validation with standard JavaServer Faces page validation functionality and other validator controls.

Default Source Code File Online Source
examples/bdc4-jsf20-validator-captcha-example.war
examples/bdc4-jsf12-validator-captcha-example.war

BotDetect CAPTCHA Spring MVC Integration Code Examples

Integration code examples show how to integrate BotDetect in your Spring MVC websites.


Java Spring MVC Basic Captcha Code Example

This code example shows the most basic source code required to protect a Spring MVC form with BotDetect CAPTCHA and validate the user input.

Default Source Code File Online Source
examples/bdc4-spring-mvc-basic-captcha-example.war

Java Spring MVC Form Captcha Code Example

This code example shows how to add BotDetect CAPTCHA protection to a typical Spring MVC form.

Captcha validation is integrated with other form fields validation, and only submissions that meet all validation criteria are accepted.

If the Captcha is successfully solved but other field validation fails, the Captcha is hidden since the users have already proven they are human.

This kind of validation could be used on various types of public forms which accept messages, and are at risk of unwanted automated submissions.

For example, it could be used to ensure bots can't submit anything to a contact form, add guestbook entries, blog post comments or anonymous message board / forum replies.

Default Source Code File Online Source
examples/bdc4-spring-mvc-form-captcha-example.war

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.