不過想要在 google app engine 上要 使用 java 自行產生的話 目前是沒有辦法的,因為BufferedImage 在 google app engine 沒有支援.....
還好搜尋了 一下找到了 reCAPTCHA 這個網站, 不久前也被Google 買下了, 不過也應為如此功能擴大很多,原本好像只有支援php 等少數語言
圖 reCAPTCHA
步驟大該如下
1. 到網頁(http://www.google.com/recaptcha/captcha)輸入Domain Name 申請驗證碼 , public key 和 private key 都要記得
2. 下載 lib (我這裡是用java 為範例,http://code.google.com/p/recaptcha/downloads/list?q=label:java-Latest)
3. 解壓縮 將 recaptcha4j-X.X.X.jar import 到專案中
4. 在專案的驗證碼加入以下的code, 包含定義 驗證後的頁面
範例code 如下
captchTest.jsp
<%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %>
<html>
<body>
<form action="captchResult.jsp" 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>
captchResult.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>
詳細的流程也可以參考 http://gaejexperiments.wordpress.com/2010/02/22/episode-15-using-a-captcha-in-your-google-app-engine-application/
參考
1. wiki 的定義
2. Google reCAPTCHA Doc
沒有留言:
張貼留言