...
Instanciate a CaptchaService
Note |
---|
title | It * must * be a * singleton* |
---|
|
|
Code Block |
---|
import com.octo.captcha.service.image.ImageCaptchaService;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
public class CaptchaServiceSingleton {
private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService();
public static ImageCaptchaService getInstance(){
return instance;
}
}
|
...
Code Block |
---|
Boolean isResponseCorrect =Boolean.FALSE;
//remenber that we need an id to validate!
String captchaId = httpServletRequest.getSession().getId();
//retrieve the response
String response = httpServletRequest.getParameter("j_captcha_response");
// Call the Service method
try {
isResponseCorrect = CaptchaServiceSingleton.getInstance().validateResponseForID(captchaId,
response);
} catch (CaptchaServiceException e) {
//should not happen, may be thrown if the id is not valid
}
//do something according to the result!
|
Want some more
Have a look to the modules provided to see how to integrate it with other frameworks.