43
3.3 MSP Functions: Expand.jsp
If you installed webMathematica as described
above
, you should be able to connect to this JSP via
http://localhost:8080/webMathematica/Examples/Expand.jsp. (You may have some other URL for accessing your
server.)
When the submit button is pressed, the polynomial is raised to the power and expanded, and an HTML page that
contains the result is returned. The source for this page is in webMathematica/Examples/Expand.jsp. A
section that shows the form tag is shown below.
<%@ page language="java" %>
<%@ taglib uri="/webMathematica taglib" prefix="msp" %>
Expanding Polynomials
Expanding Polynomials
Enter a polynomial (e.g. x+y):
Enter a positive integer (e.g. 4):
MSPBlock[{$$expr,$$num},
Expand[$$expr^$$num]]
secure computation with input variables
This page contains form and input tags as described in the previous example. Additionally, the msp:evaluate
tag refers to the MSP function
MSPBlock
.
When the form is submitted, the server connects to a Mathematica kernel, in which two symbols, $$expr and
$$num, are assigned to the text from the two input elements. If no text is entered the symbols will not have any
definition.
Mathematica now evaluates the contents of the msp:evaluate tag. The MSPBlock command is a programming
construct, which here inspects two input variables, $$expr and $$num. If either of these has no value, MSPBlock
returns a null string, which is why the first time you access the page, you do not see a result. The values of both
variables are then interpreted by Mathematica. If successful, the results of interpretation are substituted into the
second argument or body of MSPBlock. In this example all instances of $$expr are substituted with the parsed
value of $$expr, and the same is done for $$num. The result is then evaluated, formatted, and placed in the
HTML page, which is returned to the client.
Interpretation of the variables by Mathematica can fail in two ways: the input might not be valid Mathematica input
(for example, f[}), or it might be dangerous input (such as ReadList["/etc/passwd"]). In both cases, the
inputs are rejected and an error message generated. This demonstrates some of the security features of the system,
which the
Security
section documents in detail. The use of variables is discussed further in
Tips and Tricks:
Variables
.
.
<
New Page 1
Comcast Web Hosting