http://www.google.com/recaptcha
2.pom.xmlに追加。
<dependency>
<groupId>net.tanesha.recaptcha4j<groupId>
<artifactId>recaptcha4j<artifactId>
<version>0.0.7<version>
<dependency>
3.JSPでタグを追加。
<tags:captcha privateKey='XXXX' publicKey='YYYY'><tags:captcha>
4.コントローラー(サーブレット)でのパラメータと認証。
@RequestMapping(value='', method=RequestMethod.POST)
public String submitForm(@ModelAttribute('userInfo') UserInfo userInfo, @RequestParam('recaptcha_challenge_field') String challangeField, @RequestParam('recaptcha_response_field') String responseField, ServletRequest servletRequest) {
String remoteAddress = servletRequest.getRemoteAddr();
ReCaptchaResponse reCaptchaResponse = this.reCaptcha.checkAnswer(remoteAddress, challangeField, responseField);
if(reCaptchaResponse.isValid()) {
return 'success';
} else {
return 'fail';
}
}
参考リンク
http://www.javacodegeeks.com/2012/11/use-recaptcha-in-a-spring-mvc-web-application.html
https://code.google.com/p/recaptcha/wiki/HowToSetUpRecaptcha#Java/JSP
0 件のコメント:
コメントを投稿