This is documentation for an earlier version of webMathematica.
View current User Guide (Version 3.3)

Documentation3. Basic Examples


3.5 Typeset Images: Integrate.jsp

If you installed webMathematica as described above, you should be able to connect to this JSP via http://localhost:8080/webMathematica/Examples/Plot.jsp. (You may have some other URL for accessing your server.)

This example allows the user to enter a function to be integrated. The result is then formatted by the typesetting system and saved as an image. The source for this page is in webMathematica/Examples/Integrate.jsp. A section that shows the form tag is shown below.

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

<h1>Integrate a function</h1>
<form action="Integrate.jsp" method="post">Input:
   integrand = Null;            page variable to hold the integrand
   If[ MSPValueQ[ $$expr],             
      integrand =             interpret input with secure conversion
         MSPToExpression[ $$expr]] ;

<input type="text" name="expr" size="24"
value="<msp:evaluate> MSPValue[ $$expr, "Sin[x]^2"]</msp:evaluate>" />
<msp:evaluate>                  carry out the integration
   If[ integrand =!= Null,
         Integrate[integrand, x], StandardForm]]    

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

In this example, an msp:evaluate tag integrates an expression and uses MSPFormat to format the result with StandardForm. This generates an image and returns a reference to the image. For this to work, it is necessary to use the Mathematica front end.

The example also demonstrates the use of page variables with MSPToExpression. This is an alternative to using MSPBlock suitable in certain constructions, for example, when the input will be used in a number of computations. The page variable integrand is initialized to Null and later, if its value has been modified, the integration is carried out. It is assigned to the interpreted value of $$expr only if this input variable actually has a value. Note that if an error, such as a security error, is encountered in interpreting $$expr, an exception will be thrown and integrand will remain assigned to Null.

Note that MSPToExpression applies a security check to the input variable. You should be aware that input variables are a major source of danger and always use the secure conversion functions MSPBlock and MSPToExpression. In particular, you should never use ToExpression on an input variable. The Security section documents the security system in more detail.

It is also possible to return the result using MathML; this is described in greater detail in the section on MathML. A further discussion on formatting mathematics and graphics is given in the section on Displaying Mathematics and Graphics.

An interesting point about the first msp:evaluate tag is that it contains two Mathematica commands. To use two commands in the same tag they can be separated with a semi-colon ';'. In addition, the last command is also followed by a semi-colon, this makes sure that no output from the tag is inserted into the output page. More information on adding code into web Mathematica pages is given in Tips and Tricks: Coding in Pages.