All of the examples up to this point return HTML to the browser, but the web can work with general content involving many different formats. MSPReturn is provided to allow an MSP to return arbitrary content. Here is an example that demonstrates how different formats can be returned. The source is in webMathematica/Examples/Content.jsp and webMathematica/WEB-INF/Applications/ExampleUtilities/Content.m.
In this example, one evaluation tests the variable $$button. If it has a value from activating one of the buttons in the form, this is used to specify a return format type and passed to a function, GeneralContent. The Mathematica code for this function is placed into a separate package to be loaded when the variable is set. GeneralContent calls a function that creates a very simple notebook, MakeNotebook. MakeNotebook generates a notebook using the Mathematica Notebook API and the J/Link function UseFrontEnd. In a real life situation a more interesting notebook would probably be generated. MSPReturn returns the representation of the notebook to the server with the content type. This is then returned to the browser, which, if suitably configured, will deploy the necessary helper application.
In a more advanced example, the dynamically generated notebook would probably use information sent with the request from the client.
If you wish to return special content and also set a filename to be used with this content, then you may wish to use the three-argument form of MSPReturn. This is described in the MSP Function Reference section.
Another way to set the content returned from an MSP script is to use MSPPageOptions. The topic of returning general content is discussed later.