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"%>
Facelets
- add
xmlns
attribute to the page's <html>
opening tag:
xmlns:botDetect="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"
userInputID="captchaCode"
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:
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;
}
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.beta3.7.jar
botdetect-servlet-4.0.beta3.7.jar
botdetect-jsp20-4.0.beta3.7.jar
botdetect-jsf20-4.0.beta3.7.jar
In case your application uses JSF 1.2 you will need to copy the botdetect-jsf12-4.0.beta3.7.jar
file instead of botdetect-jsf20-4.0.beta3.7.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.
The free version of BotDetect Java Captcha is available as a maven artifact:
1) Add BotDetect public maven repository (NetBeans 8):
Windows -> Services -> Maven Repositories -> Add Repository:
https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/
2) In pom.xml
file, dependency should be added:
<dependency>
<groupId>com.captcha</groupId>
<artifactId>botdetect-jsf20</artifactId>
<version>4.0.beta3.7</version>
</dependency>
[...]
<repository>
<id>captcha</id>
<name>BotDetect Captcha Repository</name>
<url>https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/</url>
</repository>
In case your application uses JSF 1.2 you will need to add botdetect-jsf12
instead of botdetect-jsf20
.
BotDetect Java Captcha library's Maven artifact can be added as a Gradle dependency:
1) Add BotDetect public Maven repository to build.gradle
file:
repositories {
maven {
url "https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/"
}
...
}
2) Since BotDetect Java Captcha Maven artifact is not available on "mavenCentral", to use it as an external dependency, BotDetect Java Captcha repository must be defined:
dependencies {
...
compile 'com.captcha:botdetect-jsf20:4.0.beta3.7'
...
}
The highlighted code defines dependency:
Group ID: com.captcha
Artifact ID: botdetect-jsf20
Version: 4.0.beta3.7
In case your application uses JSF 1.2 you will need to add botdetect-jsf12
instead of botdetect-jsf20
.
The BotDetect Java Captcha Library (available in our git.captcha.com repository) can be added into an Ant project using Ivy.
ivy-settings.xml -- Ivy configuration file
Ivy needs repository information configured (in ivy-setting.xml file) in order to download BotDetect Java Captcha Maven artifact:
<ivysettings>
<properties file="build.properties" />
<settings defaultResolver="default-chain"/>
<resolvers>
<chain name="default-chain">
<ibiblio name="botdetect" root="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:" m2compatible="true"/>
...
</chain>
</resolvers>
</ivysettings>
ivy.xml -- file containing dependency descriptions
To complete BotDetect Java Captcha installation, we need to define dependency in ivy.xml file:
<ivy-module version="2.0">
<info organisation="org.apache" module="WebProject" />
<!-- Classpath management, thanks Maven -->
<configurations>
<conf name="compile" description="compile dependencies"/>
<conf name="runtime" description="runtime dependencies" extends="compile"/>
<conf name="test" description="test dependencies" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="com.captcha" name="botdetect-jsf20" rev="4.0.beta3.7" conf="compile->default"/>
...
</dependencies>
</ivy-module>
In case your application uses JSF 1.2 you will need to add botdetect-jsf12
instead of botdetect-jsf20
.
Finally, we add target
to your project's build.xml in order to get Dependencies.
<target name="resolve" description="retrieve dependencies with ivy">
<echo message="Getting dependencies..." />
<ivy:retrieve />
<ivy:cachepath pathid="compile.path" conf="compile" />
<ivy:cachepath pathid="runtime.path" conf="runtime" />
<ivy:cachepath pathid="test.path" conf="test" />
</target>
ivy: retrieve
retrieves all the dependencies of the last resolve call to a lib directory.
Add target
to application's Buildfile to get the BotDetect Java Captcha Library jar from git.captcha.com repository:
<!-- Download dependence -->
<target name="get-deps" description="retrieve dependencies manually">
<echo message="Getting dependencies..." />
<mkdir dir="lib" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect/4.0.beta3.7/botdetect-4.0.beta3.7.jar" dest="lib/botdetect-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-servlet/4.0.beta3.7/botdetect-servlet-4.0.beta3.7.jar" dest="lib/botdetect-servlet-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-jsp20/4.0.beta3.7/botdetect-jsp20-4.0.beta3.7.jar" dest="lib/botdetect-jsp20-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-jsf20/4.0.beta3.7/botdetect-jsf20-4.0.beta3.7.jar" dest="lib/botdetect-jsf20-4.0.beta3.7.jar" usetimestamp="true" />
...
</target>
In case your application uses JSF 1.2 you will need to add botdetect-jsf12
instead of botdetect-jsf20
.
BotDetect Java Captcha Api is now ready to be used in project.
Reference the target 'get-deps'
from previous step in a compile target:
<target name="compile" depends="init, get-deps" description="compile source code">
<copydir src="${web.dir}" dest="${build.dir}" />
<mkdir dir="${web.classes.dir}" />
<javac destdir="${web.classes.dir}" source="${jdk.version}" target="${jdk.version}"
debug="true" includeantruntime="false" classpathref="compile.path">
<src path="${src.dir}" />
</javac>
</target>
1. Show a CAPTCHA Challenge on the JSP Form
Add the following to the very top of the web form's (you want to protect against bots) source file:
<%@page import="com.captcha.botdetect.web.servlet.Captcha"%>
To render Captcha in the form, add the following within <form> you want to protect against bots:
<%
// Adding BotDetect Captcha to the page
Captcha captcha = Captcha.load(request, "exampleCaptcha");
captcha.setUserInputID("captchaCode");
String captchaHtml = captcha.getHtml();
out.write(captchaHtml);
%>
<input id="captchaCode" type="text" name="captchaCode" />
2. Validate User's Captcha Input During Form Submission
On form submit, the Captcha validation result must be checked:
<%
if ("POST".equalsIgnoreCase(request.getMethod())) {
// validate the Captcha to check we're not dealing with a bot
boolean isHuman = captcha.validate(request.getParameter("captchaCode"));
if (isHuman) {
// TODO: Captcha validation passed, perform protected action
} else {
// TODO: Captcha validation failed, show error message
}
}
%>
In-Depth JSP CAPTCHA Instructions and Explanations
Detailed JSP Captcha instructions and explanations can be found in the JSP Captcha integration how to guide.
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 three jar files from BotDetect Java download package to application's WEB-INF/lib
folder:
botdetect-4.0.beta3.7.jar
botdetect-servlet-4.0.beta3.7.jar
botdetect-jsp20-4.0.beta3.7.jar
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.
The free version of BotDetect Java Captcha is available as a maven artifact:
1) Add BotDetect public maven repository (NetBeans 8):
Windows -> Services -> Maven Repositories -> Add Repository:
https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/
2) In pom.xml
file, dependency should be added:
<dependency>
<groupId>com.captcha</groupId>
<artifactId>botdetect-jsp20</artifactId>
<version>4.0.beta3.7</version>
</dependency>
[...]
<repository>
<id>captcha</id>
<name>BotDetect Captcha Repository</name>
<url>https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/</url>
</repository>
BotDetect Java Captcha library's Maven artifact can be added as a Gradle dependency:
1) Add BotDetect public Maven repository to build.gradle
file:
repositories {
maven {
url "https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/"
}
...
}
2) Since BotDetect Java Captcha Maven artifact is not available on "mavenCentral", to use it as an external dependency, BotDetect Java Captcha repository must be defined:
dependencies {
...
compile 'com.captcha:botdetect-jsp20:4.0.beta3.7'
...
}
The highlighted code defines dependency:
Group ID: com.captcha
Artifact ID: botdetect-jsp20
Version: 4.0.beta3.7
The BotDetect Java Captcha Library (available in our git.captcha.com repository) can be added into an Ant project using Ivy.
ivy-settings.xml -- Ivy configuration file
Ivy needs repository information configured (in ivy-setting.xml file) in order to download BotDetect Java Captcha Maven artifact:
<ivysettings>
<properties file="build.properties" />
<settings defaultResolver="default-chain"/>
<resolvers>
<chain name="default-chain">
<ibiblio name="botdetect" root="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:" m2compatible="true"/>
...
</chain>
</resolvers>
</ivysettings>
ivy.xml -- file containing dependency descriptions
To complete BotDetect Java Captcha installation, we need to define dependency in ivy.xml file:
<ivy-module version="2.0">
<info organisation="org.apache" module="WebProject" />
<!-- Classpath management, thanks Maven -->
<configurations>
<conf name="compile" description="compile dependencies"/>
<conf name="runtime" description="runtime dependencies" extends="compile"/>
<conf name="test" description="test dependencies" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="com.captcha" name="botdetect-jsp20" rev="4.0.beta3.7" conf="compile->default"/>
...
</dependencies>
</ivy-module>
Finally, we add target
to your project's build.xml in order to get Dependencies.
<target name="resolve" description="retrieve dependencies with ivy">
<echo message="Getting dependencies..." />
<ivy:retrieve />
<ivy:cachepath pathid="compile.path" conf="compile" />
<ivy:cachepath pathid="runtime.path" conf="runtime" />
<ivy:cachepath pathid="test.path" conf="test" />
</target>
ivy: retrieve
retrieves all the dependencies of the last resolve call to a lib directory.
Add target
to application's Buildfile to get the BotDetect Java Captcha Library jar from git.captcha.com repository:
<!-- Download dependence -->
<target name="get-deps" description="retrieve dependencies manually">
<echo message="Getting dependencies..." />
<mkdir dir="lib" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect/4.0.beta3.7/botdetect-4.0.beta3.7.jar" dest="lib/botdetect-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-servlet/4.0.beta3.7/botdetect-servlet-4.0.beta3.7.jar" dest="lib/botdetect-servlet-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-jsp20/4.0.beta3.7/botdetect-jsp20-4.0.beta3.7.jar" dest="lib/botdetect-jsp20-4.0.beta3.7.jar" usetimestamp="true" />
...
</target>
BotDetect Java Captcha Api is now ready to be used in project.
Reference the target 'get-deps'
from previous step in a compile target:
<target name="compile" depends="init, get-deps" description="compile source code">
<copydir src="${web.dir}" dest="${build.dir}" />
<mkdir dir="${web.classes.dir}" />
<javac destdir="${web.classes.dir}" source="${jdk.version}" target="${jdk.version}"
debug="true" includeantruntime="false" classpathref="compile.path">
<src path="${src.dir}" />
</javac>
</target>
1. Show a CAPTCHA Challenge on the Spring MVC Form
We'll assume you already have a form which can be posted (<form method="post" ...
), with other fields in place.
BotDetect custom captcha
tag is designed to add CAPTCHA protection to Spring MVC form as simple as possible.
At the top of the file put BotDetect taglib
declaration:
<%@taglib prefix="botDetect" uri="https://captcha.com/java/jsp"%>
To display the Captcha test on your form, you will need the following Html elements:
- A textbox for the Captcha code user input, with a label displaying Captcha instructions
- The Captcha markup including the image, sound and reload icons etc., which will be generated by the Captcha tag.
For example:
<botDetect:captcha id="exampleCaptcha" userInputID="captchaCode"/>
<div class="validationDiv">
<input id="captchaCode" type="text" name="captchaCode"
value="${basicExample.captchaCode}"/>
<input type="submit" name="submit" value="Submit" />
<span class="correct">${basicExample.captchaCorrect}</span>
<span class="incorrect">${basicExample.captchaIncorrect}</span>
</div>
When you open your form in a browser, the markup given above should render similar as:
2. Validate User's Captcha Input During Form Submission
On form submit, the Captcha validation result must be checked in controller:
Captcha captcha = Captcha.load(request, "exampleCaptcha");
boolean isHuman = captcha.validate(basicExample.getCaptchaCode());
if (isHuman) {
// TODO: Captcha validation passed, perform protected action
} else {
// TODO: Captcha validation failed, show error message
}
return new ModelAndView("index", "basicExample", basicExample);
This approach is shown in the BotDetect Spring MVC Basic CAPTCHA integration code example included in the BotDetect download package.
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 three jar files from BotDetect Java download package to application's WEB-INF/lib
folder:
botdetect-4.0.beta3.7.jar
botdetect-servlet-4.0.beta3.7.jar
botdetect-jsp20-4.0.beta3.7.jar
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.
The free version of BotDetect Java Captcha is available as a maven artifact:
1) Add BotDetect public maven repository (NetBeans 8):
Windows -> Services -> Maven Repositories -> Add Repository:
https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/
2) In pom.xml
file, dependency should be added:
<dependency>
<groupId>com.captcha</groupId>
<artifactId>botdetect-jsp20</artifactId>
<version>4.0.beta3.7</version>
</dependency>
[...]
<repository>
<id>captcha</id>
<name>BotDetect Captcha Repository</name>
<url>https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/</url>
</repository>
BotDetect Java Captcha library's Maven artifact can be added as a Gradle dependency:
1) Add BotDetect public Maven repository to build.gradle
file:
repositories {
maven {
url "https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/"
}
...
}
2) Since BotDetect Java Captcha Maven artifact is not available on "mavenCentral", to use it as an external dependency, BotDetect Java Captcha repository must be defined:
dependencies {
...
compile 'com.captcha:botdetect-jsp20:4.0.beta3.7'
...
}
The highlighted code defines dependency:
Group ID: com.captcha
Artifact ID: botdetect-jsp20
Version: 4.0.beta3.7
The BotDetect Java Captcha Library (available in our git.captcha.com repository) can be added into an Ant project using Ivy.
ivy-settings.xml -- Ivy configuration file
Ivy needs repository information configured (in ivy-setting.xml file) in order to download BotDetect Java Captcha Maven artifact:
<ivysettings>
<properties file="build.properties" />
<settings defaultResolver="default-chain"/>
<resolvers>
<chain name="default-chain">
<ibiblio name="botdetect" root="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:" m2compatible="true"/>
...
</chain>
</resolvers>
</ivysettings>
ivy.xml -- file containing dependency descriptions
To complete BotDetect Java Captcha installation, we need to define dependency in ivy.xml file:
<ivy-module version="2.0">
<info organisation="org.apache" module="WebProject" />
<!-- Classpath management, thanks Maven -->
<configurations>
<conf name="compile" description="compile dependencies"/>
<conf name="runtime" description="runtime dependencies" extends="compile"/>
<conf name="test" description="test dependencies" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="com.captcha" name="botdetect-jsp20" rev="4.0.beta3.7" conf="compile->default"/>
...
</dependencies>
</ivy-module>
Finally, we add target
to your project's build.xml in order to get Dependencies.
<target name="resolve" description="retrieve dependencies with ivy">
<echo message="Getting dependencies..." />
<ivy:retrieve />
<ivy:cachepath pathid="compile.path" conf="compile" />
<ivy:cachepath pathid="runtime.path" conf="runtime" />
<ivy:cachepath pathid="test.path" conf="test" />
</target>
ivy: retrieve
retrieves all the dependencies of the last resolve call to a lib directory.
Add target
to application's Buildfile to get the BotDetect Java Captcha Library jar from git.captcha.com repository:
<!-- Download dependence -->
<target name="get-deps" description="retrieve dependencies manually">
<echo message="Getting dependencies..." />
<mkdir dir="lib" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect/4.0.beta3.7/botdetect-4.0.beta3.7.jar" dest="lib/botdetect-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-servlet/4.0.beta3.7/botdetect-servlet-4.0.beta3.7.jar" dest="lib/botdetect-servlet-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-jsp20/4.0.beta3.7/botdetect-jsp20-4.0.beta3.7.jar" dest="lib/botdetect-jsp20-4.0.beta3.7.jar" usetimestamp="true" />
...
</target>
BotDetect Java Captcha Api is now ready to be used in project.
Reference the target 'get-deps'
from previous step in a compile target:
<target name="compile" depends="init, get-deps" description="compile source code">
<copydir src="${web.dir}" dest="${build.dir}" />
<mkdir dir="${web.classes.dir}" />
<javac destdir="${web.classes.dir}" source="${jdk.version}" target="${jdk.version}"
debug="true" includeantruntime="false" classpathref="compile.path">
<src path="${src.dir}" />
</javac>
</target>
1. Show a CAPTCHA Challenge on the Struts Form
We'll assume you already have a form which can be posted (<form method="post" ...
), with other fields in place.
BotDetect custom captcha
tag is designed to add CAPTCHA protection to Struts 2 form as simple as possible.
At the top of the file put BotDetect taglib
declaration:
<%@taglib prefix="botDetect" uri="https://captcha.com/java/jsp"%>
To display the Captcha on your form, you will need the following Html elements:
- A textbox for the Captcha code user input, with a label displaying Captcha instructions
- The Captcha markup including the image, sound and reload icons etc., which will be generated by the Captcha tag.
For example:
<botDetect:captcha id="exampleCaptcha" userInputID="captchaCode"/>
<s:textfield name=
"captchaCode" id=
"captchaCode"/>
<s:submit name=
"submit" label=
"Submit" id=
"submit"/>
And you also need to add exclude directive for CaptchaServlet to Struts 2 filter by adding the following in your
struts.xml
configuration file:
<constant name="struts.action.excludePattern" value="/botdetectcaptcha"/>
2. Validate User's Captcha Input During Form Submission
On form submit, the Captcha validation result must be checked in Struts Action:
[...]
public class BasicCaptchaAction extends ActionSupport {
private String captchaCode;
public String getCaptchaCode() {
return captchaCode;
}
public void setCaptchaCode(String captchaCode) {
this.captchaCode = captchaCode;
}
public String execute() {
return SUCCESS;
}
public void validate() {
Captcha captcha = Captcha.load(ServletActionContext.getRequest(), "exampleCaptcha");
boolean isHuman = captcha.validate(captchaCode);
if (!isHuman) {
addFieldError("captchaCode", "Incorrect code");
}
}
}
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 three jar files from BotDetect Java download package to application's WEB-INF/lib
folder:
botdetect-4.0.beta3.7.jar
botdetect-servlet-4.0.beta3.7.jar
botdetect-jsp20-4.0.beta3.7.jar
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.
The free version of BotDetect Java Captcha is available as a maven artifact:
1) Add BotDetect public maven repository (NetBeans 8):
Windows -> Services -> Maven Repositories -> Add Repository:
https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/
2) In pom.xml
file, dependency should be added:
<dependency>
<groupId>com.captcha</groupId>
<artifactId>botdetect-jsp20</artifactId>
<version>4.0.beta3.7</version>
</dependency>
[...]
<repository>
<id>captcha</id>
<name>BotDetect Captcha Repository</name>
<url>https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/</url>
</repository>
BotDetect Java Captcha library's Maven artifact can be added as a Gradle dependency:
1) Add BotDetect public Maven repository to build.gradle
file:
repositories {
maven {
url "https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/"
}
...
}
2) Since BotDetect Java Captcha Maven artifact is not available on "mavenCentral", to use it as an external dependency, BotDetect Java Captcha repository must be defined:
dependencies {
...
compile 'com.captcha:botdetect-jsp20:4.0.beta3.7'
...
}
The highlighted code defines dependency:
Group ID: com.captcha
Artifact ID: botdetect-jsp20
Version: 4.0.beta3.7
The BotDetect Java Captcha Library (available in our git.captcha.com repository) can be added into an Ant project using Ivy.
ivy-settings.xml -- Ivy configuration file
Ivy needs repository information configured (in ivy-setting.xml file) in order to download BotDetect Java Captcha Maven artifact:
<ivysettings>
<properties file="build.properties" />
<settings defaultResolver="default-chain"/>
<resolvers>
<chain name="default-chain">
<ibiblio name="botdetect" root="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:" m2compatible="true"/>
...
</chain>
</resolvers>
</ivysettings>
ivy.xml -- file containing dependency descriptions
To complete BotDetect Java Captcha installation, we need to define dependency in ivy.xml file:
<ivy-module version="2.0">
<info organisation="org.apache" module="WebProject" />
<!-- Classpath management, thanks Maven -->
<configurations>
<conf name="compile" description="compile dependencies"/>
<conf name="runtime" description="runtime dependencies" extends="compile"/>
<conf name="test" description="test dependencies" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="com.captcha" name="botdetect-jsp20" rev="4.0.beta3.7" conf="compile->default"/>
...
</dependencies>
</ivy-module>
Finally, we add target
to your project's build.xml in order to get Dependencies.
<target name="resolve" description="retrieve dependencies with ivy">
<echo message="Getting dependencies..." />
<ivy:retrieve />
<ivy:cachepath pathid="compile.path" conf="compile" />
<ivy:cachepath pathid="runtime.path" conf="runtime" />
<ivy:cachepath pathid="test.path" conf="test" />
</target>
ivy: retrieve
retrieves all the dependencies of the last resolve call to a lib directory.
Add target
to application's Buildfile to get the BotDetect Java Captcha Library jar from git.captcha.com repository:
<!-- Download dependence -->
<target name="get-deps" description="retrieve dependencies manually">
<echo message="Getting dependencies..." />
<mkdir dir="lib" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect/4.0.beta3.7/botdetect-4.0.beta3.7.jar" dest="lib/botdetect-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-servlet/4.0.beta3.7/botdetect-servlet-4.0.beta3.7.jar" dest="lib/botdetect-servlet-4.0.beta3.7.jar" usetimestamp="true" />
<get src="https://git.captcha.com/botdetect-java-captcha.git/blob_plain/HEAD:/com/captcha/botdetect-jsp20/4.0.beta3.7/botdetect-jsp20-4.0.beta3.7.jar" dest="lib/botdetect-jsp20-4.0.beta3.7.jar" usetimestamp="true" />
...
</target>
BotDetect Java Captcha Api is now ready to be used in project.
Reference the target 'get-deps'
from previous step in a compile target:
<target name="compile" depends="init, get-deps" description="compile source code">
<copydir src="${web.dir}" dest="${build.dir}" />
<mkdir dir="${web.classes.dir}" />
<javac destdir="${web.classes.dir}" source="${jdk.version}" target="${jdk.version}"
debug="true" includeantruntime="false" classpathref="compile.path">
<src path="${src.dir}" />
</javac>
</target>
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.
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
OS |
Application Server |
Java |
Browser |
Supported Operating Systems:
|
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+
|
Officially Supported Browsers*:
- Chrome 49+
- Edge 20+
- Firefox 52+
- IE 8+
- Opera 36+
- Safari (OSX) 5+
- Safari (iOS 6+)
Numerous other browsers are not officially supported but the captcha still works.
Read the notes below!
|
*
'Officially Supported Browsers' are those browsers for which we do the testing in order to ensure that
both the image and audio captcha options are working properly.
Nonetheless, both the image and audio captcha options are working properly in the most of non-archaic
** browsers anyway -- officially-supported, or not -- while the image
captcha option alone works in all of them!
If you find our 'Officially Supported Browsers' policy too-restrictive check Recaptcha the Stalker's
one that says:
We guess that after checking the Recaptcha's policy -- you will consider ours as the accommodative one :).
**
Archaic browsers?
At present, our 'Archaic Browsers' policy works this way:
Or, in the less nice words:
-
If those last remaining few laggards cannot be bothered to update their browsers --
we cannot be bothered neither -- nor you should be!
-
Half of the Internet is broken for them since years ago anyway -- and they do not seem to care!
Please Note
BotDetect Java Captcha Library v4.0.Beta3.7 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.