Adding Captcha Fields
To use captcha validation support in the actions, the checkCaptcha
parameter needs to be set
to true
in the Struts action configuration. When this parameter is set,
the action enforces captcha validation. For example, if we want to add captcha validation to the
/blog/add
action which is an instance of
the class com.ndc.usercontent.struts.actions.save.SaveArticle
, we need the following configuration.
<action path="/blog/add" name="articleForm" parameter="articleType=blog;checkCaptcha=true" type="com.ndc.usercontent.struts.actions.save.SaveArticle"> <!-- Other action configuration stuff --> </action>
Once the above configuration is in place, we can write JSP segment as part of an HTML form to show the captcha challenge interface. Please see Advanced Developer Guide for instructions.
When the user's input captcha code is wrong, the action will direct the user to the configured error page (which in common case is the same page where the user is filling the form). Have a look at Creating Articles to get an overview on how to configure the error URL. Here is the JSP fragment to show captcha error in error page:
<logic:messagesPresent message="true" property="CAPTCHA"> <p class="fieldError"> <html:messages id="error" message="true" bundle="Validation" property="CAPTCHA"> <bean:write name="error"/><br /> </html:messages> </p> </logic:messagesPresent>
The following VCE Struts actions come with built-in support for captcha verification:
-
com.ndc.usercontent.struts.actions.save.SaveArticle
-
com.ndc.usercontent.struts.actions.save.SaveGroupProfile
-
com.ndc.usercontent.struts.actions.save.SaveUserProfile