Documentation3. Basic Examples

 

Hello.jsp

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

This example evaluates the Date[] function of Mathematica. The result changes each time the page is accessed, demonstrating that this really is a dynamic process. The source for this page is in webMathematica/Examples/Hello.jsp.

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


<html>                              standard html tags
   <head>
      <title>Hello World (The MSP Taglib)</title>
   </head>
   <body>
      <h1>Hello World (The MSP Taglib)</h1>
      <msp:allocateKernel>            allocate a Mathematica kernel
         <h4>Date[]</h4>
      <msp:evaluate>
      Date::usage                     evaluated by Mathematica
      </msp:evaluate>

      <p>Its current value is:</p>
      <msp:evaluate>
          Date[]                     evaluated by Mathematica
      </msp:evaluate>
      </msp:allocateKernel>            free the Mathematica kernel
   </body>
</html>

This page uses standard HTML tags as well as special webMathematica tags; these have the form <msp:tag>. The webMathematica tags are executed from the top of the page to the bottom. The <msp:allocate> tag causes a Mathematica kernel to be allocated to use for computations. The contents of the <msp:evaluate> tags are sent to Mathematica for computation with the result inserted into the final page. The </msp:allocate> tag frees the Mathematica kernel to be used for another computation.