Processing a JSP

This section will describe the different stages that are involved in processing a JSP for webMathematica.

A JSP is processed as part of an HTTP transaction. A client sends a request to the server, which replies with a response. One feature of HTTP requests is that they can send parameters and values to the server. This is essential for any dynamic behavior, because parameters are used to select and control the response. The response could be an HTML page. However, it could be some other content type, such as an image, a Mathematica notebook, or some form of XML.

The JSP is processed by the servlet container in which it is running, it is processed in a top-down method, so that commands at the top are evaluated before commands lower down. A JSP interacts with webMathematica by means of the custom tags defined in the webMathematica tags. A sample page is shown below.

<%@ page language="java"  %>
<%@ taglib uri="http://www.wolfram.com/msp" prefix="msp" %>
<html>
<title>page</title>
<body>
<msp:evaluate>
eval1
</msp:evaluate>
<msp:evaluate>
eval2
</msp:evaluate>
</body>
</html>

The first evaluate tag allocates a Mathematica kernel to use for computations, assigning input variables and parameters, and other initialization. Note that the kernel that was allocated will be available in a clean state.

The evaluate tags then use the allocated Mathematica kernel to evaluate their input. Note that any assignments or definitions made in one evaluate tag will be visible in another.

When the page is finished the Mathematica kernel is released, first cleaning it of any definitions that were made. If any special processing is needed, for example, to deal with exceptions it will be carried out at this point.

It should be noted that there are a number of other special tags that can be used; these are detailed in the section on the webMathematica tags, as are more details on the working of the evaluate tag.