Table of ContentsPreviousNext

Put your logo here!


4 Developing JavaServer Pages for MapleNet

MapleNet JavaServer Pages (JSP) allow you to use HTML pages to display Maple calculations. Maple expressions can be inserted in web page sources and rendered within web browsers.

In this Chapter

4.1 Prerequisites

The server must support the use of JavaServer Pages. For example, a compatible server is Tomcat 5.5.

4.2 Creating MapleNet JSP Content

To display Maple content on the web, you must add special tags to web page sources. The tags follow normal HTML tag conventions in that they are either of the single tag form

<tag ... tag parameters .../>

or matched opening and closing tags of the form

< tag ... tag parameters ...>
... data ...
</tag>

For example, in static HTML pages most of the page text is enclosed in HTML and body tags, as in the following.

<html>
<body>
This is a simple page.
</body>
</html>

To begin creating MapleNet JSP content, follow the instructions in the Page Setup and Using Maple Tags sections of this chapter.

4.3 Page Setup

The server must recognize Maple specific tags. All tags in the page are processed in the order encountered on the source pages.

  1. Add a taglib directive before the <html> tag at the top of the document. This allows the server to recognize Maple specific tags.

<%@ taglib prefix="maple" uri="/maplemath.tld" %>

where

Technical Note: In the default install, the WEB-INF/web.xml file instructs the JSP engine to map the /maplenet.tld uri to the WEB-INF/tlds/maplenet.tld file.
  1. Add a page tag following the taglib directive. This allows the server to maintain user data between pages requested by the user.
<%@ page session="true" %>

where

4.4 Using Maple Tags

This section describes the init, statement, code, assign, plot, and release tags.

Initialization Tag

Add an init (initialization) tag to indicate how the Maple kernel is to be used. Use the following syntax.

<maple:init scope="[tag|page|request|session]" debug="[false|true]" />

where

Statement Tag

The statement tag executes one or more Maple expressions, with the result of the expression(s) being inserted directly into the resultant HTML page. The form of the tag is as follows.

<maple:statement lastline="[false|true]" breakline="[true|false]" type="[text|plot]" width="value" height="value" safeHTML="[true|false]" quotes="[true|false]">

... Maple expression ...

... Maple expression ...

</maple:statement>

If the result is Maple output, it is inserted as text. If the result is a plot, the plot is converted to an image, and an HTML <img ...> tag is inserted in the page.

Important: Each line in the statement block is executed separately. Therefore, all the code for control structures, such as if/else and try/catch must be on the same line. For example:

if (x>0) then s := +1; else s:=-1; end if

When using both parameters, consider the following inserted into web page content.
<maple:statement breakline=... lastline=... >

1+1; 2+2; 3+3;
7;
8;
9;

<maple:statement>
Table 6 illustrates how the above input is displayed in a web browser based on parameter usage.

Table 6: Output in Browser
Parameter Values
breakline
true
false
lastline
true
9
9
false
2 4 6
7
8
9
2 4 6789

The following illustrates how content is processed and displayed using the examples given in Table 6.

 

If lastline is true and breakline is true, all lines are processed but only the result of the last line is displayed. Therefore all four lines of data

1+1; 2+2; 3+3;
7;
8;
9;
are sent to Maple, but only the last result is displayed and an HTML <br> string is appended after the line.
9<br>
If lastline is true and breakline is false, all lines are processed but only the result of the last line is displayed. Therefore all four lines of data
1+1; 2+2; 3+3;
7;
8;
9;
are sent to Maple, but only the last result is displayed.
9
If lastline is false and breakline is true, all lines are processed and displayed. Therefore all 4 lines of data
1+1; 2+2; 3+3;
7;
8;
9;
are sent to Maple, resulting in MapleNet producing
2 4 6<br>
7<br>
8<br>
9<br>
The browser displays this as
2 4 6
7
8
9
If lastline is false, and breakline is false, all lines are processed and displayed. Therefore all four lines of data
1+1; 2+2; 3+3;
7;
8;
9;
are sent to Maple, resulting in MapleNet producing
2 4 6
7
8
9

Note: browsers typically ignore white space, so the result is displayed as the following.

2 4 6789

Code Tag

The code tag is similar to the <maple:statement ...> tag, but no data is generated to the output page. This can be used to define common procedures and data for later use by expressions in the <maple:statement ...> sections. The form of the tag is as follows.

<maple:code>

... Maple expression ....

... Maple expression ....

</maple:code>

This tag has no parameters. Each expression in the tag body is evaluated by the Maple kernel.

Note: Unlike the statement block, all expressions are evaluated together. As such, control structures (if/else, try/catch) can span several lines.

Assign Tag

The assign tag allows parameters from HTML forms to be passed as variables to Maple. The form of the tag is as follows.

<maple:assign param="param name" variable="Maple variable" default="def value" />

where

Although the <maple:xxx> tags appear in the source, they do not appear in the user browser because they are converted by the Maple Tag Library into content that is consistent with web pages. The content is the output from the Maple kernel.

Plot Tag

The plot tag creates an interactive (dynamic image) plot. The form of the tag is as follows.

<maple:plot width="value" height="value"> Maple_plot_equation</maple:plot>

where

plot3d(sin(x^0.5*y^0.5), x=-Pi..Pi,y=-2*Pi..2*Pi,axes=BOXED)

For static plots, see Statement Tag.

Release Tag

The release tag terminates the JSP connection to Maple, allowing other JSP sessions to access the Maple server. The form of the tag is as follows.

<maple: release />

This tag will immediately release Maple, regardless of the scope setting in the init tag. This is the preferred method of freeing Maple for other user sessions.

4.5 Examples

To understand more about MapleNet JavaServer Pages, review the following integration.jsp and MaplePlotTest.jsp example code listings.

Integration Example

The following example is similar to the applet example (Listing 3) for performing simple integration. However, it uses only web page tags and no client-side Java.

Listing 7 Integration.jsp

<%@ taglib prefix="maple" uri="/maplemath.tld" %>

<%@ page session="true" %>

<maple:init scope="session" debug="false" />

<maple:assign param="expr001" variable="eqn" default="sin(x)" />

<maple:code>

  doInt := proc()

    global eqn;

    int(eqn, x);

  end proc;

</maple:code>



<html>

  <head>

    <title>

      Sample Integration

    </title>

  </head>

  <body>

    <center>

      <h1>Sample Integration</h1>

      <form method="post"

            action="Integration.jsp" >

        <table width="50%" >

          <tr>

            <td width="35%">Enter Expression : </td>

            <td width="65%">

              <input type="text"

                     size="40"

                     name="expr001"

                     value="<maple:statement>eqn</maple:statement>" >

            </td>

          </tr>

          <tr>

            <td width="35%">Result : </td>

            <td width="65%">

              <input type="text"

                     size="40"

                     name="result001"

                     value="<maple:statement>doInt()</maple:statement>" >

            </td>

          </tr>

        </table>

        <input type="submit"

               name="Calculate"

               value="Submit">

      </form>

    </center>

    <maple:statement type="plot" height="200" width="400"> plot(eqn, x=0..10)</maple:statement>

  </body>

  <maple:release />

</html>

The following discussion refers to Listing 7.

When the Calculate button is clicked, the form is submitted to the server to be processed again by Integration.jsp. This time the <maple:assign ...> tag takes the user input from the expr001 field and assigns it to eqn. The new value of eqn is integrated and placed in the output page in the result001 field.

Plot Example

The following code provides an example of static and interactive plots.

Listing 8 MaplePlotTest.jsp

<%@ taglib prefix="maple" uri="/maplemath.tld" %>

<%@ page session="true" %>

<maple:init scope="page" debug="true" />

<maple:assign param="eqn001" variable="plt_eqn" default="plot3d(sin(x^0.5*y^0.5), x=-Pi..Pi, y=-2*Pi..2*Pi,axes=BOXED)" />

<html>

  <head>

    <title>MaplePlotTest</title>

  </head>

  <body bgcolor="#ffffc0">

    <h1>Test of Maple Plot Tag</h1>

    Time is <%= new java.util.Date().toString() %>

    <br>

    <center>

      <b> Static Image plot</b>

      <br>

      <maple:statement type="plot" width="250" height="200" >plot(cos(4*x),x=0..10)</maple:statement>

    </center>

    <br>

    <center>

      <b>Dynamic Image plot</b>

      <br>

      <maple:plot width="500" height="300" >plt_eqn</maple:plot>

    </center>

    <br>

    <center>

      <form method="post">

        <br>

        <input type="text"

               size="50"

               name="eqn001"

               value="plot3d(sin(x^0.5*y^0.5), x=-Pi..Pi, y=-2*Pi..2*Pi,axes=BOXED)" >

        <br>

        <input type="submit"

               name="Submit"

               value="Submit">

        <input type="reset"

               value="Reset">

      </form>

    </center>

    <maple:release/>

  </body>

</html>

A static plot is displayed above an interactive plot. The user can submit new values for the interactive plot in an input field.

4.6 Publishing JSP Content to the MapleNet Server

Publishing a JSP to the MapleNet server requires copying the JSP file to the appropriate directory on the server. The file can be copied to the server using any network file transfer tool, such as FTP, SSH, or WebDAV.

Consult your site administrator for specific details on where your files should be placed and what method should be used to transfer them.

Once the file is copied to the server, your content will be available by accessing the appropriate URL. For example, if your JSP is mypage.jsp, then assuming the MapleNet server is myserver.com and that your worksheet was transferred to the jsp directory of the MapleNet web application, the worksheet can be accessed by pointing your browser to http://myserver.com/maplenet/jsp/mypage.jsp.

Consult your site administrator for the exact URL to access your content.


Table of ContentsPreviousNext