The Mathematica Journal
Departments
Feature Articles
Columns
New Products
New Publications
Classifieds
Calendar
News Bulletins
Mailbox
Letters
FAQ
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Home
Download this Issue

Mathematica Server Pages

Mathematica Server Pages (MSP) technology is the foundation of webMathematica. It is based on a standard Java technology called servlets. Servlets are special Java programs that run on a web server machine. Typically, support is provided by a separate program called a servlet container (or sometimes a servlet engine), which connects to the web server. Essentially, all modern web servers support servlets natively or through a plug-in servlet container. This includes Apache, Microsoft's IIS and PWS, Netscape Enterprise Server, iPlanet, and application servers (such as IBM WebSphere).

MSP technology allows a site to contain HTML pages that are enhanced by the addition of Mathematica commands. When a request is made for one of these pages, which are called MSP scripts, Mathematica commands are evaluated and the computed result is placed in the page.

MSP Scripts

MSP scripts contain HTML that is marked up with Mathematica commands. They are easy to write and fit well with HTML development mechanisms such as HTML editors. Here is a sample MSP script.

<html>
<head>
<title>Expanding Polynomials</title>
</head>
<body>
<h1>Expanding Polynomials</h1>
<form action="Expand" method="post">
Enter a polynomial (eg x+y):
<input type="text" name="expr" size="10">
Enter a positive integer (eg 4):
<input type="text" name="num" size="3">
<br>

<%Mathlet
MSPBlock[{$$expr,$$num},
Expand[$$expr^$$num]] %>

<br>
<input type="submit" name="button" value="Evaluate">
</form>
</body>
</html>

Click here to see this example running live.

This is very much standard HTML except for the Mathlet tag. It contains the Mathematica commands that are to be evaluated when the page is requested from the server. Here the input polynomial, referenced by the variable $$expr, is raised to the power given by $$num, and expanded. The web page that is sent back to the client contains the computed result. MSPBlock is a command provided by webMathematica for working with input sent with an HTTP request. There is a large collection of Mathematica commands for working with web requests and responses that take care of features such as plotting, formatting and typesetting, embedding applets, and returning general content.

Setting Up

Setting up a webMathematica site involves first installing and configuring a server that supports Java servlets. When this is running, the webMathematica tools are then installed on the server. These contain all the material that is necessary to support the site, including the following items.

  • A Mathematica application--support for the Mathematica commands
  • A Mathematica session manager--software for launching and shutting down Mathematica sessions, as well as support for configuring and monitoring
  • A Web Application--an application for loading into the servlet container
  • Example MPS scripts
  • Sample configuration files
  • Documentation
  • Applets
  • Images

Technology Overview

The core of the webMathematica site is the MSP servlet. It uses the Mathematica session manager, a useful application that maintains a pool of Mathematica sessions that are waiting to be used. When a request is received, the MSP servlet obtains a Mathematica kernel and uses it to process the MSP script. When this is finished, the kernel is returned to the pool and the result returned to the browser. A given Mathematica session is reused many times, which leads to an improvement in performance. This arrangement allows one server to work with more than one Mathematica kernel, allowing concurrent computations.

The result of a request to a webMathematica site can be anything that can be generated by Mathematica: this includes HTML, MathML, XML, images, and Mathematica notebooks. The results can interoperate with applets, javascript, plug-ins and Active-X controls.

The Mathematica session manager takes care of launching and initializing Mathematica kernels. It also takes care of shutting down sessions that exceed a preset limit for computations. The whole system is fully configurable to provide detailed control of a particular site.

An overview of the steps in processing a page is shown below. For the sake of illustration, it has a Mathematica session pool with three sessions.


Copyright © 2001 Wolfram Media, Inc. All rights reserved.

[Article Index][Prev Page][Next Page]