Wiki » History » Revision 4
Revision 3 (Soh Keong, 09/22/2004 03:16 AM) → Revision 4/5 (Soh Keong, 09/22/2004 03:25 AM)
{{toc}} h1. Wiki h1. Guides h2. Demo URL The URL is: > http://192.168.2.68:8080/TestPage/page/captcha/recaptcha.jsp h2. Steps By Steps h3. Registration Create Public Key and Private Key # Visit http://www.google.com/recaptcha/admin # Sign in with your email and password (If no account with google, please proceed with sign up.) # After sign in, Click on 'Add a New Site' button. # Enter domain name in the text field, and click on the 'Create Key' button. # Now, Public Key and Private Key is generated. h3. Client site JSP <pre> <%@ 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> </pre> h3. Server site JSP <pre> <%@ 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> </pre> h3. 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: * # https://www.google.com/recaptcha (Retrieved 29 July2013) # https://developers.google.com/recaptcha/docs/java (Retrieved 29 July2013)