This is documentation for an earlier version of webMathematica.

 Documentation8. Classic webMathematica Technology

This section will discuss how to convert between MSP scripts and JSPs that use the MSP Taglib. First, most Mathematica commands that can be used in an MSP can also be used in a JSP, so it is possible to convert from an MSP to a JSP. The only Mathematica command that cannot be used in a JSP is MSPInclude. If you need to use this functionality, it should be modified to use jsp:include. However, the JSP mechanism is richer than the MSP mechanism, consequently, some JSPs are harder to convert back to MSPs.

This will be explained with the Plot.msp example, the text of which is shown below.

<html>
<title>Plot</title>
<body>
<h1>Plot</h1>
<form action="Plot" method="post">
Enter a function:
<input type="text" name="fun" size="24"
value="<%Mathlet MSPValue[ \$\$fun, "Sin[x]^2"] %>">
Enter a number:
<input type="text" name="x1" size="24"
value="<%Mathlet MSPValue[ \$\$x1, "10"] %>">
<br/>
<%Mathlet
MSPBlock[{\$\$fun, \$\$x1},
MSPShow[Plot[\$\$fun, {x, 0, \$\$x1}]]] %>
<hr/>
<input type="submit" name="btnSubmit" value="Evaluate">
</form>
</body>
</html>

The corresponding JSP, Plot.jsp, is shown below.

<%@ page language="java" %>
<%@ taglib uri="/webMathematica-taglib" prefix="msp" %>

<html>
<title>Plot</title>
<body bgcolor="#ffffff" >

<form action="Plot.jsp" method="post">

<msp:allocateKernel>
Enter a function:
<input type="text" name="fun" size="24" value =
"<msp:evaluate>MSPValue[ \$\$fun, "Sin[x]^2"]</msp:evaluate>"
/>
Enter a number:
<input type="text" name="x1" size="24" value =
"<msp:evaluate>MSPValue[ \$\$x1, "10"]</msp:evaluate>"
/>
<br>
<msp:evaluate>
MSPBlock[ {\$\$fun, \$\$x1},
MSPShow[ Plot[\$\$fun, {x, 0, \$\$x1}]]]
</msp:evaluate>
<hr>
</msp:allocateKernel>

<input type="submit" name="btnSubmit" value="Evaluate">

</form>
</body>
</html>

The differences are quite apparent and are summarized as follows:

The script must be renamed to be a JSP.

The script must be placed in the webMathematica web application (not inside the WEB-INF directory).

The following lines must be added to the top of the script.

<%@ page language="java" %>
<%@ taglib uri="/webMathematica-taglib" prefix="msp" %>

All evaluations must be contained inside a single <msp:allocateKernel>.

<%Mathlet expr %> must be replaced with <msp:evaluate>expr</msp:evaluate>.

No change to the Mathematica computations is needed other than changing uses of MSPInclude to use jsp:include.

If Mathematica packages are loaded from within the MSPDirectory, these should be placed in a directory in WEB-INF/Applications.

It is possible to convert from a JSP that uses the MSP Taglib back to an MSP by simply reversing the steps shown in the previous section. This will only work if no other JSP features are being used and if the only MSP Taglib tags that are used are msp:allocateKernel and msp:evaluate.