Captcha servlet ver. 1.2

    Java servlet lets you deploy captcha in your applications.

How to use it:

a) copy captchaPackage.jar into WEB-INF/lib directory

b) describe CaptchaServlet servlet in your web.xml file. You can provide the following optional parameters:

width - width for the image. Default value is 75
height - height for the image. Default value is 35
size - font size. Default value is 17


    <servlet>
     <servlet-name>CaptchaServlet</servlet-name>
     <servlet-class>com.jsos.image.CaptchaServlet</servlet-class>
    </servlet>

c) describe a mapping for this servlet in web.xml file
 


<servlet-mapping>
  <servlet-name>CaptchaServlet</servlet-name>
  <url-pattern>/servlet/captcha</url-pattern>
</servlet-mapping>

and now you can use servlet in your JSP pages. For example:
 


<form method="post" action="controller.jsp">
Human test:
<input type="text" name="human"/>
<img src="http://your_host/servlet/captcha" border="0" alt="Captcha image"/>
</form>

Servlet display an image for the captcha and saves the captcha string in HTTP session attribute captcha. So in your server-side processing you can compare the input from your form and the value from the session. E.g. in file controller.jsp:
 


<%
String captcha = (String)session.getAttribute("captcha");
String typed = request.getParameter("human");

if (!captcha.equals(typed))
{
  ....
}
%>

for downloading:

servlet: captchaPackage.jar  

 © Coldbeans Software     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in Coldtags: