Verifying the CAPTCHA Response

The following example contains the Java code you need to add to a custom Struts action or servlet class in order to verify a CAPTCHA response:

Bus bus = ApplicationBus.getApplicationBus(servletContext);
CaptchaProviderFactory captchaProviderFactory =
    (CaptchaProviderFactory) bus.lookupSafe("/com/escenic/captcha/CaptchaProviderFactory");

CaptchaProvider captchaProvider = captchaProviderFactory.getCaptchaProvider();
boolean isValidCaptchaResponse = captchaProvider.checkCaptchaResponse(httpServletRequest);

An alternative approach is to create a generic servlet filter that you can then use to filter all requests that require CAPTCHA verification.

If you are using either Viz Community Expansion or the Forum plug-in then you do not need to write your own verification code, since both of these plug-ins include Struts action classes that perform CAPTCHA verification. For details see the documentation of these plug-ins.