Project

General

Profile

Actions

Wiki

Guides

Demo URL

The URL is:

http://192.168.2.68:8080/TestPage/page/captcha/recaptcha.jsp

Steps By Steps

Registration

  1. Visit http://www.google.com/recaptcha/admin
  2. Sign in with your email and password (If no account with google, please proceed with sign up.)
  3. After sign in, Click on 'Add a New Site' button.
  4. Enter domain name in the text field, and click on the 'Create Key' button.
  5. Now, Public Key and Private Key is generated.

Client site JSP

    <%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
    <%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %>

    <html>
      <body>
        <form action="" method="post">
        <%
          ReCaptcha c = ReCaptchaFactory.newReCaptcha("your_public_key", "your_private_key", false);
          out.print(c.createRecaptchaHtml(null, null));
        %>
        <input type="submit" value="submit" />
        </form>
      </body>
    </html>

Server site JSP

    <%@ page import="net.tanesha.recaptcha.ReCaptchaImpl" %>
    <%@ page import="net.tanesha.recaptcha.ReCaptchaResponse" %>

    <html>
      <body>
      <%
        String remoteAddr = request.getRemoteAddr();
        ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
        reCaptcha.setPrivateKey("your_private_key");

        String challenge = request.getParameter("recaptcha_challenge_field");
        String uresponse = request.getParameter("recaptcha_response_field");
        ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);

        if (reCaptchaResponse.isValid()) {
          out.print("Answer was entered correctly!");
        } else {
          out.print("Answer is wrong");
        }
      %>
      </body>
    </html>

DNS Caching (Important)

-Dsun.net.inetaddr.ttl=30 to your app-server to avoid connection between your server and reCAPTCHA to be interrupted every few months.

References

  1. https://www.google.com/recaptcha (Retrieved 29 July2013)
  2. https://developers.google.com/recaptcha/docs/java (Retrieved 29 July2013)

Updated by Soh Keong almost 20 years ago ยท 5 revisions