Developing Your Own Pages
Once you have installed and configured a Wolfram Web Engine server so that the examples run correctly and have studied the basics of writing material for the Wolfram Web Engine as described previously, you are ready to start developing your own material.
One way to start is to make your own area in the MSP web application. You could make a directory here (for example, NewScripts) and copy one of the samples (for example, Plot.jsp) from the Examples directory. You could then access this script with the URL http://localhost:8080/webengine/NewScripts/Plot.jsp.
When you actually want to write your own material, you may look at the tips and tricks described in this chapter. The chapter continues to describe other page-development utilities that are part of the Wolfram Web Engine.
Wolfram Workbench
Wolfram Workbench provides tools for developing solutions and applications based on Wolfram products such as Wolfram Engine and gridMathematica. It also includes support for the Wolfram Web Engine.
More information can be found in the Workbench documentation, but the following gives a summary of some of the main features.
Wolfram Web Engine Projects
Wolfram Workbench is a project-based system, and to work with the Wolfram Web Engine, it supports a type of Wolfram Web Engine project. This allows you to develop your webpages and Wolfram Language code, perhaps archiving it in a code repository. You can test the individual components and then deploy them to the server to actually use them.
Syntax Support for JSP Pages
Wolfram Workbench provides a variety of syntax support for JSP pages. This includes showing XML, HTML and JSP syntax errors. Of particular value are reports on Wolfram Language syntax errors inside of evaluate tags.
Authoring Pages
Wolfram Workbench provides a number of tools that help in writing JSP and HTML pages. These include command completion and preview features. In addition, a palette is provided that allows templates for entire page structures to be added.
Wizards
Wolfram Workbench offers a number of wizards for creating Wolfram Web Engine material, such as an entire project or a new webpage.
Server Interaction Tool
Wolfram Workbench contains a tool that works with the actual server. From this, you can carry out tasks such as starting or stopping the server, deploying your project and connecting with a debug session.
Full Wolfram Web Engine Documentation
Wolfram Workbench contains the Wolfram Web Engine user guide along with other material specific to the Workbench tools. This is probably the most convenient way to read the documentation.
Debugging for Wolfram Language Code
Wolfram Workbench provides a debugger for Wolfram Language code. You can use this debugger to connect to the server and follow your code as it executes, setting breakpoints to halt in particular locations.
More information is available in the debugging section.
Tips and Tricks
This section provides a summary of a few issues that will help you to get started writing your own pages. These are all described in more detail in later sections of the documentation, but are collected together here in a brief description. Getting a good grasp of these points will help you to make progress in developing your site.
Variables
There are two types of variables that are important for you to understand when you are getting started with MSP: input variables and page variables.
Input variables come with the HTTP web request, for example from an input field in an HTML form. You can identify input variables in Wolfram Language code because they are labeled with a $$ prefix. In the following example, the setting variable may be sent from an input field. In Wolfram Language code, it is called $$setting:
<input type="text" name="setting" />
<msp:evaluate>
If[ MSPValueQ[ $$setting],
....
]
</msp:evaluate>
You should be aware that input variables are a potential security risk to your server. Therefore, you should always use the special functions MSPBlock and MSPToExpression for converting into Wolfram Language input. In particular, you should never use ToExpression on an input variable. An example of using MSPBlock is shown here:
<input type="text" name="fun" />
<msp:evaluate>
MSPBlock[ {$$fun},
Integrate[ $$fun, x]
]
</msp:evaluate>
Page variables are Wolfram Language variables that you use to hold intermediate values. They are called page variables since they are cleared when the page is finished. In the following example, the page variable tmp is used to hold the expression that was entered into the text input field (which is held in an input variable called $$expr). Note the use of the secure function MSPToExpression to convert the Wolfram Language expression from the input:
<input type="text" name="expr" />
<msp:evaluate>
tmp = Null;
tmp = MSPToExpression[ $$expr] ;
</msp:evaluate>
<p>
<msp:evaluate>
If[ tmp =!= Null,
....
]
</msp:evaluate>
</p>
If you want your variable to persist from one page to another, you can declare it as a session variable. This and further details of variables are discussed in detail in Advanced Topics: Variables.
Coding in Pages
The purpose of MSP tags is to use Wolfram Language for web computation; a key part of this is placing Wolfram Language code in your webpages. This is done with evaluate tags, as follows:
<msp:evaluate>
Integrate[ 1/(1-x^3),x]
</msp:evaluate>
Note that the Wolfram Language code will evaluate in the typical way for Mathematica and the result of the computation will appear in the webpage. You can use MSPFormat to change the way that the result is formatted; more information on formatting in MSP is found in Advanced Topics: Evaluation Formatting. An example of MSPFormat is shown here; this formats the integral into TraditionalForm using a GIF image to display the result:
<msp:evaluate>
MSPFormat[ Integrate[ 1/(1-x^3),x], TraditionalForm]
</msp:evaluate>
If you do not wish to see the result in the web output, you can suppress it by using a semicolon (;). In the following example, an assignment is made to the variable x, but no output appears:
<msp:evaluate>
x = 109;
</msp:evaluate>
A final tip for working with code in MSP pages is the separation of multiple computations in a single evaluate tag by using a semicolon:
<msp:evaluate>
x = 109;
y = 44.5;
{x+y}
</msp:evaluate>
More information on coding in MSP pages is found in Appendix: MSP Taglib, which gives a detailed reference on the MSP tags.
Templates
The Wolfram Web Engine provides a number of templates and other utilities that can be used to incorporate more design into your MSP material.
Design Examples
As you develop your own material, you may wish to look at the design examples. These are a collection of samples that make use of colors, fonts and images for a more professional appearance. You can access the design examples from the main index page, or with a URL such as http://localhost:8080/webengine/DesignTemplates/DesignTemplate1.jsp.
Banners and Buttons
A collection of banners and buttons are available for use in your pages, which you can find with the link http://localhost:8080/webengine/BannersImages. To use one of these images, such as the banner webm-white.gif, you can use an img tag like the following:
The section on including static files has more information on how to include images.
Minimal Installation
When you have confirmed that your Wolfram Web Engine site is running correctly and you start to develop your own material, you may wish to strip out all of the documentation and examples to get a minimal installation. The minimum set of files for the Wolfram Web Engine is that everything in the WEB-INF directory must be kept.
Minimal File Layout
Additionally, you can remove all the J/Link native libraries from WolframWebEngine/WEB-INF/lib/SystemFiles/Libraries except for the library required for your system, which is located in a directory named by $$SystemID.