11.07.2015 Views

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Data in HttpSessionswebMathematica User Guide 105Enter a file to upload: To generate suitable data,click hereThis example shows how data can be stored in HttpSessions for processingby webMathematica.This is very similar to Upload.html, except that it calls the JSP Session.jsp when the form issubmitted. Session.jsp is shown below.file = "FileName" /. MSPGetUploadFile[];data = Flatten[N[Import[file, "Table"]]];MSPSessionVariable[UploadedData, Null];UploadedData = data;This short JSP reads the data that was uploaded, and then uses MSPSessionVariable to storethe data in a session variable named UploadedData. This is a very convenient way to store datapersistently from one HTTP request to another. The data is actually stored in the server, so thateven if the Mathematica kernel was restarted, the data would still be available. The storageuses what is known as an HTTP session and the server may use cookies or some other mechanismto actually store the data. This is how a shopping cart in an e-commerce website works.As far as a developer of a webMathematica website is concerned, it is all very simple; just usethe function MSPSessionVariable, giving it the name of the variable and an initial value. Afterthe data has been read, there is a jsp:forward to the page that actually does the computationsand plots, Data3.jsp. Often it is a very good design principle to divide the code over a numberof separate pages that all do different tasks; if you develop pages that have large amounts ofcomplicated code in them, then refactoring might improve your system. A selection of SessionÖProcess.jsp is shown below.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!