9.5 Dynamic HTML
When the web was first developed, it supported only distribution of static pages. The technology was extended to allow interactive access for dynamic content generation.
Fundamentally, the web is driven by its main protocol, HTTP (Hyper Text Transfer Protocol), which imposes certain constraints. Under HTTP, a client sends a request to a server that replies with a response. A crucial feature of HTTP is that it is stateless; that is, after processing a request, no record of that request is kept. Of course, state information can be maintained via some other mechanism; for example, the servlet API has methods for keeping state that can be used with MSPSessionVariable.
This reference section reviews server and client technologies for dynamic web content. Because this field changes very rapidly the survey is not intended to be exhaustive.
9.5.1 Server Technology
There are several server-side technologies for dynamic content. These include CGI scripting, Active Server Pages, server plug-ins, Perl scripting, and Java servlets and JavaServer Pages.
CGI scripts provided the original server technology for dynamic content. Under CGI, an executable, such as a shell script or compiled binary, is launched on every request.
This mechanism is limited in a number of key ways. It is relatively expensive since it requires launching a new CGI process for every request, which can cause scalability problems. One solution is to make the actual CGI script a lightweight process that communicates with its own server; many web solutions actually do this. Of course this requires nontrivial development and can result in something that is more complicated to use than other dynamic solutions.
Active Server Pages
Active Server Pages (ASPs) are a scripting language for dynamic web content, developed by Microsoft. They are quite common and powerful. At present, ASPs are not supported, but this will be continually reviewed.
Most HTTP servers provide some type of extensibility that can be used to support special features for interactivity. The problem with this approach is that it is not very portable.
Perl is often used as a scripting language either with CGI or a server plug-in. Technologies exist to link Mathematica to Perl, but these are not as developed as is the technology for linking to Java.
Java Servlets and JavaServer Pages
Java Servlet technology provides a high-level API (programming interface) for working with HTTP requests. There are many ways that web servers can be enhanced to add a servlet engine. Solutions exist for all web servers and run on all major platforms.
The Servlet API is a high-level interface that provides functions both for maintaining information while the server is running and for working with HTTP requests and responses.
JavaServer Pages (JSPs) are a closely related technology that make it very convenient for servlets to return HTML; the server converts a JSP into a servlet, which is then executed.
webMathematica is implemented with a mixture of Java Servlet and JavaServer Pages technology.
9.5.2 Client Technology
The fundamental content delivered by web servers is HTML, a tree-structured language formed from tags. At present, HTML is being transitioned into a stricter language, XHMTL, an XML application.
HTML is fundamental to the topic of dynamic web content, so here is a short primer on dynamic web content with HTML.
First, start with a basic HTML document.
<p>Welcome to my page.</p>
This could be downloaded from a web server and rendered in a web browser.
Active elements are added to HTML by form and input elements, which can be included inside an HTML document. Here is a form element.
<form action="http://myhost/active" method="post">
The form has two attributes, an action attribute and a method attribute. When the form is activated, it will make a connection to this URL and use the post method.
Often the URL will be located on the same server from which the page was downloaded. In this case it is common to use a relative URL.
<form action="active" method="post">
A form element may contain input elements, which add various buttons and input fields. Here is an example of a form with two input tags: the first allows us to enter some text, and the second causes the form to be submitted.
<form action="active" method="post">
<input type="text" name="ARG1">
<input type="SUBMIT" name="button" value="Compute">
When the form is activated by the submit input tag, the browser makes a request to the URL referred to by the action attribute. It sends the name and value pairs from all of the input tags in the form. This is the most basic way to activate HTML.
One thing to remember about form elements is that the name/value pairs can be specified in the URL. You may have seen them in something like http://myserver/document?ARG1=10&ARG2=20.
Some of the examples are designed to work with applets.
The major browsers, Internet Explorer, Mozilla, and Netscape Navigator, continue to develop new interactive technologies at a rapid pace. It may be advantageous for webMathematica users to consider new technologies as they become available.