If you installed webMathematica as described above, you should be able to connect to this MSP via http://localhost:8080/webMathematica/Examples/Variables.jsp. (You may have some other URL for accessing your server.) It demonstrates how variables are connected to input values. The source for this page is in webMathematica/Examples/Variables.jsp.
<form action="Variables.jsp" method="post"> html form <msp:allocateKernel> Enter something: <br> <input type="text" name="tmp" size="10" /> field for user input <br> <br> <msp:allocateKernel> <msp:evaluate>$$tmp</msp:evaluate> evaluated by Mathematica </msp:allocateKernel> <br> <input type="submit" name="submitButton" value="Evaluate" /> button for activating form </msp:allocateKernel> </form> </body> </html>
This page is more elaborate because it contains form and input elements. These are important ways for allowing interaction from the client.
A form element is a block of HTML that may contain input elements. A form may be activated with an input of type submit; this sends the name and value associated with each input tag to the server. Here, the opening tag of the form element contains two attributes. The action attribute refers to a URL that is accessed when the form is activated. In this case, it is a relative URL that refers to the original Variables script. The method attribute tells the browser what HTTP method to use, in this case, a post method. (It is very common to use post methods.)
This example has two input tags: the first allows the user of the page to enter text, and the second specifies a button that, when pressed, will submit the form. When the form is submitted, it will send information from input elements to the URL specified by the action attribute (in this case, the same JSP). Text entered into the input tag, which uses the name tmp, will be assigned to the input variable $$tmp.
The first time the page is accessed there is no value for $$tmp. When a value is entered in the text field and the Evaluate button pressed, $$tmp gets a value which is displayed. Note that the value is a Mathematica string—if you try and enter a computation such as "5+7", no computation is actually done. If you want the input to be interpreted and evaluated by Mathematica, you need to use one of the MSP functions that are described later in this chapter.
Note that the $$ prefix is used to label input variables; these are variables that are sent with the HTTP request. The use of variables is discussed further in Tips and Tricks: Variables.