Extended Page Language
webMathematica provides a number of extended ways for a server computation to direct the contents of the resulting web page. These are in addition to the basic tags such as evaluate.
Expression Language
webMathematica support for the expression language gives a more concise way to call to Mathematica than typically done in the evaluate tag. It is also much more suitable to be nested inside another tag or an attribute.
<input type="text" name="fun" size="24"
value = "${msp:evaluate(' MSPValue[ $$fun, \"Sin[x]^2\"]')}">
The expression language form of evaluate is more concise and neater than the alternative version that relies on nesting an evaluate tag.
<input type="text" name="fun" size="24" value =
"<msp:evaluate> MSPValue[ $$fun, "Sin[x]^2"] </msp:evaluate> "
>
The expression language is particularly useful for working with the standard tags.
JSP Standard Tags
The Java Server Pages technology, on which webMathematica is based, provides a number of libraries of standard tags for carrying out a variety of useful purposes such as controlling flow within the web page. The libraries for these tags are included with webMathematica. If you want to use them, you must include an extra declaration at the top of your web page.
if
The if tag is useful for conditionally adding a section of a web page. An example is JSTLif.jsp, found in the webMathematica web application in the directory Examples/ExtendedLanguage (the full path in Tomcat would be webapps/webMathematica/Examples/ExtendedLanguage). Some of the contents are shown below.
<c:if test="${msp:evaluate('MSPValueQ[$$test]')}">
<p>
The input variable had a value: ${msp:evaluate('$$test')}.
</p>
</c:if>
<c:if test="${msp:evaluate('!MSPValueQ[$$test]')}">
<p>
The input variable did not have a value.
</p>
</c:if>
In this example, if the input paramater $$test has a value, then the contents of the first if are included in the output page; this also shows the value of the parameter. On the other hand, if the parameter does not have a value, for example this is the first request, then the contents of the second if are included in the output page.
set
The set tag is a convenient way to store a result that can be used in other locations. An example is JSTLset.jsp, found in the webMathematica web application in the directory Examples/ExtendedLanguage (the full path in Tomcat would be webapps/webMathematica/Examples/ExtendedLanguage). Some of the contents are shown below.
In this example, if the variable id is initialized with the result of a Mathematica computation. This is then used in a number of other instances of the expression language.
choose/when/otherwise
The choose, when, and otherwise tags are another way to conditionally add blocks of text. An example is JSTLchoose.jsp, found in the webMathematica web application in the directory Examples/ExtendedLanguage (the full path in Tomcat would be webapps/webMathematica/Examples/ExtendedLanguage). Some of the contents are shown below.
<c:set var="id" value="${msp:evaluate('$$test')}" />
<c:choose>
<c:when test="${id == 'Sin'}">
<p>Sin was chosen</p>
</c:when>
<c:when test="${id == 'Cos'}">
<p>Cos was chosen</p>
</c:when>
<c:when test="${id == 'Tan'}">
<p>Tan was chosen</p>
</c:when>
<c:otherwise>
<p>Something else was chosen</p>
</c:otherwise>
</c:choose>
In this example, the variable id is initialized with the result of a Mathematica computation. This is then used in a number of different when or otherwise tags. The final page depends on what was stored in the input parameter.