From NewWiki

WebMathematica

Contents

This is about webMathematica 2.1

Install

I have only tested the installation under windows. Everything is well explained. You should be able to play with the samples in about 10 minutes (plus your download time for tomcat and Java).

The old webMathematica 1.0 required to install 2 elements, one for tomcat and the other for Mathematica. The new installation is simpler as you only need to install the tomcat side.

An important positive element of the documentation is that the troubleshooting really explains clearly what can go wrong and what it looks like when that happens. It is simple to verify that tomcat is running because it comes with its own page and test samples (and troubleshooting).

first steps

After playing with the samples, I created a package and then used the package in the sample. To create a package I always copy the sample package found in the help system under demos. It is the notation package.

The package just needs to be saved in the proper directory and referenced in the config file of webMathematica.

Two common mistakes are:

  • to forget to properly export a function. Then of course the function will not exist and do nothing.
  • to forget to set the cell as an initialization cell. then the cell is not exported in the package.

Source code included

even though one does not need to know java (and I did not), java is a pretty simple language will a lot of references on the internet. WebMathematica comes with the source code for its implementation, so you can read the source file and get some idea of how it works.

One thing I found usefull was to look as MSP.m the package. You can add Print statements in there and see the results in the tomcat log file.

You can also use JLink in your package rather than in the jsp file. For example if you want to change the timeout value of the "Session" between tomcat and a user:

SetSessionTimeOut[seconds_] := Module[{result = "", session},
session = $ServletRequest@getSession[True];
session@setMaxInactiveInterval[seconds];
];

geSession is a member function of request which is accessible through the global variable $ServletRequest.

debugging help

All http parameters are transformed into variables for the kernel between the allocateKernel calls.

By adding code like this at the end of your page you can see what parameters were passed with values:


httpNames = Select[Names["$$*"],Symbol[#]!=#&];
StringJoin @@((ToString[#]<>"="<>ToString[Symbol[#]]<>"
\n")& /@ httpNames)

Another piece of code in your package for example might help you display the session variables:

GetSessionVariables[] := 
Module[{result = "", name, value, session, enumeration},
session = $ServletRequest@getSession[True];
result = result <> "Session Information" <>
"getMaxInactiveInterval=" <> ToString[session@getMaxInactiveInterval[]];   
result = result <> "variables and values:";  
enumeration = session@getAttributeNames[];
While[enumeration@hasMoreElements[],
name = enumeration@nextElement[];
value = session@getAttribute[name];
result = result <> name <> "=" <> ToString[value];
];
ToString[result]
];

Session variables and cookies

Because MSPSessionVariables are implemented using the Java session variables, they do not last longer than the browser session. This means that when the user closes the browser, the data is not retrievable. Sometimes you want data to last longer, as for example with this site, the user wants the web site to remember its login information.

This can be implemented easily using J/Link and the cookies from Java:

nameCookie = JavaNew["javax.servlet.http.Cookie", "userName", wpName];
nameCookie@setPath["/webMathematica"];
If[deployed, nameCookie@setDomain["www.mathematica-users.org"];];
nameCookie@setMaxAge[when];
myCookieResult = $ServletResponse@addCookie[nameCookie];

You might notice the If[deployed... statement. One known issue of the Java cookies is that they only work on the localhost you might use for debugging if you do not set the Domain name. This statement makes sure we do so only on the deployed server.

More to come

As I progress and learn more about the package while implementing this web site I will add more of my learnings here.

Luc

Links

Contributors to this Page The 2 contributors to this page (ordered by date of first contribution):
User Latest Contribution # Contributions
1. LucB Thu 2 Jun 2005 04:54:11 8
2. tttrung Thu 1 Sep 2005 08:51:56 1

This page was created by LucB on Thu 2 Jun 2005 04:54:11 and last updated by tttrung on Thu 1 Sep 2005 08:51:56
Retrieved from WebMathematica .
Personal tools