Wednesday, March 23, 2011

Integration reCaptcha with Spring MVC

When I was explaining about reCaptcha on my previous entry, I made reference to my little-store example app, which basically has a bunch of frameworks (the idea is implement those technologies that I want to learn or just practice).

What I did is really simple, the first step was adding my new dependency to my POM
Then add to my webApplicationContext.xml my new reCaptcha bean
You must get the keys from the official website by adding your site. On my case I put the keys in a properties file, and then by using spring I loaded that file


Next in my Controller I used my ReCaptcha bean, like this
As you could see, this code populates a variable (reCaptcha) which I'm going to display on my JSP using JSTL:
${requestScope.reCaptcha}
Inside of a HTML FORM

Finally, this is how I validated the confirmation text (you must be expecting these 2 params: recaptcha_challenge_field and recaptcha_response_field)

The only problem I faced was related to my flow (which screen should I display), but besides that the implementation is really straight forward, simple!

No comments:

Post a Comment