This example passes values computed in a JSP into Mathematica where they are used for computation by Mathematica. This example uses the Java programming language which makes it different from most webMathematica examples which do not require any Java programming. The source for this page is in webMathematica/Examples/SetBasic.jsp and is shown below.
<p> This jsp uses the MSP Taglib to demonstrate passing Java values to Mathematica. </p>
<% int num = 10; Object obj = new Object(); %>
<msp:set name="var1" intValue="<%= num %>" /> <msp:set name="var2" objectValue="String from java" /> <msp:set name="var3" objectValue="<%= obj %>" />
<msp:evaluate> Nest[ f, x, var1] </msp:evaluate>
<msp:evaluate> Characters[ var2] </msp:evaluate>
<msp:evaluate> var3@hashCode </msp:evaluate>
In this example, a variable num, which is an int, str, which is a String, and obj, which is an Object, are created in the JSP. These are then passed to Mathematica using the msp:set tag. This tag takes two attributes, the name attribute gives the name that the variable will be given in Mathematica, while the value attribute refers to the value. If the variable is of a primitive type, such as int, char, or double, then it needs to use the appropriate value attribute, such as intValue, charValue, or doubleValue. Notice how msp:set sends a Java int as a Mathematica integer and a Java String as a Mathematica string. The Java Object is sent as a Mathematica object reference. The rules that govern how types are sent from Java to Mathematica are exactly those that J/Link uses.