Displaying Your CAPTCHA Challenge
Once you have correctly configured CAPTCHA support, the JSP code shown
below can be used to add a CAPTCHA challenge to a Struts form in your
publication templates (the html:
prefix in some of
the tag names identifies them as members of the standard Struts HTML tag
library). The code examples assume that you want to add the CAPTCHA
challenge to a form that users will use to create blog entries.
ReCaptcha
<html:form action="/blog/add"> <!-- JSP code to render the form properties related to creating a blog --> <div class="captcha"> <captcha:recaptchaHTML theme="red" lang="en"/> </div> <!-- The rest of the JSP code to render the form properties related to creating a blog goes here. --> </html:form>
In this example, the <captcha:recaptchaHTML/>
tag generates the HTML code required to display the ReCaptcha challenge.
JCaptcha
<html:form action="/blog/add"> <!-- JSP code to render the form properties related to creating a blog --> <div class="captcha"> <label for="jcaptcha_response">Verification code: </label> <input id="jcaptcha_response" type="text" name="jcaptcha_response" /><br/> <html:image page="/jcaptcha.do"/> </div> <!-- The rest of the JSP code to render the form properties related to creating a blog goes here. --> </html:form>
The input
element called
jcaptcha_response
is the field in which the user is
required to enter the characters displayed in the CAPTCHA image. The tag
<html:image page="/jcaptcha.do"/>
generates an
ordinary HTML img
element containing the CAPTCHA
challenge image.