Math question taglib ver. 1.2

    Custom JSP taglib. Lets you provide a "human test" for you input. Tag MathQuestion generates a random expression and saves the result in session scope. You can ask about this result in your HTML form and compare the input with the value saved in session. It could be a proof that your page is not submitted from some automated application (math captcha). For example:

<%@ taglib uri="taglib.tld" prefix="q" %>

<form ... >
  <q:MathQuestion />

and you will get some like this:

2 - 8 =

you can disable automatic generation for the input filed and do it by your own. E.g.:

<%@ taglib uri="taglib.tld" prefix="q" %>

<form ... >
  <q:MathQuestion input="false" />
  <%=_Expression%> = <input type="text" name="answer">

in your servlet (JSP page) processes the input you can compare two value:
session.getAttribute("_Answer") and request.getParameter("answer").

Actually tag creates the following page scope variables:

_Expression (type is java.lang.String) - generated expression
_Operand1 (type is java.lang.Integer) - the first operand
_Operation (type is java.lang.String) - generated operation
_Operand2 (type is java.lang.Integer) - the second operand
_Answer (type is java.lang.Integer) - the answer. This value is saved also in the session scope.

Tags are:


tag generates a random math question. Parameters are:

1) cond Optional attribute. Describes a boolean value tag's behavior depends on. Default value is true (create a captcha)
2) input Optional attribute. Describes a boolean value. If this value is true than tag will automatically output input field too. Default value is true.
3) className Optional attribute. Describes a CSS class for input field.
4) style Optional attribute. Describes a CSS style for input field.

for downloading:

Library: mquestiontag.jar    Description: taglib.tld

 © Coldbeans      Comments, suggestions?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: