jcaptcha
web.xml:
<servlet>
<servlet-name>jcaptcha</servlet-name>
<servlet-class>com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jcaptcha</servlet-name>
<url-pattern>/jcaptcha.jpg</url-pattern>
</servlet-mapping>
web-inf/lib:
commons-collections-3.2
commons-logging-1.0.4
filters-2.0.235
jcaptcha-2.0-alpha-1-SNAPSHOT
jcaptcha-api-1.0
jcaptcha-integration-simple-servlet-2.0-alpha-1-SNAPSHOT
jsp:
<script type="text/javascript">
function refresh() {
var image = document.getElementById("jcaptcha.jpg");
image.src = "jcaptcha.jpg?" + Math.floor(Math.random() * 1000)
}
</script>
...
<img src="jcaptcha.jpg" id="jcaptcha.jpg" />
<input type="text" name="jcaptcha" value="" class="required" />
<input type="button" value="更換驗證碼" onClick="javascipt:refresh()">
servlet check:
String userCaptchaResponse = request.getParameter("jcaptcha");
boolean captchaPassed = SimpleImageCaptchaServlet.validateResponse(request, userCaptchaResponse);
if(captchaPassed){
// proceed to submit action
}else{
// return error to user
}
Reference
https://jcaptcha.atlassian.net/wiki/display/general/Simple+Servlet+Integration+documentation
<servlet>
<servlet-name>jcaptcha</servlet-name>
<servlet-class>com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jcaptcha</servlet-name>
<url-pattern>/jcaptcha.jpg</url-pattern>
</servlet-mapping>
web-inf/lib:
commons-collections-3.2
commons-logging-1.0.4
filters-2.0.235
jcaptcha-2.0-alpha-1-SNAPSHOT
jcaptcha-api-1.0
jcaptcha-integration-simple-servlet-2.0-alpha-1-SNAPSHOT
jsp:
<script type="text/javascript">
function refresh() {
var image = document.getElementById("jcaptcha.jpg");
image.src = "jcaptcha.jpg?" + Math.floor(Math.random() * 1000)
}
</script>
...
<img src="jcaptcha.jpg" id="jcaptcha.jpg" />
<input type="text" name="jcaptcha" value="" class="required" />
<input type="button" value="更換驗證碼" onClick="javascipt:refresh()">
servlet check:
String userCaptchaResponse = request.getParameter("jcaptcha");
boolean captchaPassed = SimpleImageCaptchaServlet.validateResponse(request, userCaptchaResponse);
if(captchaPassed){
// proceed to submit action
}else{
// return error to user
}
Reference
https://jcaptcha.atlassian.net/wiki/display/general/Simple+Servlet+Integration+documentation
留言
張貼留言