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.

134 webMathematica User GuideInformal Web ServicesInformal web services do not use a special protocol, and this means that a client needs to knowdetails of how the server passes data. The advantage of an informal web service is that it iseasy to set up. One use of an informal web service is for a program running inside a browser tomake a call to the server. Examples are a JavaScript program using AJAX or an Actionscriptprogram running in the Flash runtime. In fact, the webMathematica interactive tools, based onMSPManipulate, use an informal web service to send details of the user interface that is to beconstructed to the Flash runtime.AJAX ExampleThis example uses AJAX technology to demonstrate the setting up of an informal web service. Itwill not discuss all the details of how AJAX works, which is covered in the section on using AJAXwith webMathematica.The source for this example can be found in the webMathematica web application in the directoryExamples/AJAX (the full path in Tomcat would be webapps/webMathematica/Examples/AJAX). The two files are LoadXML.jsp, which contains the AJAX code to call to the server, andReturnXML.jsp, which returns the result from the server. If your server is configuredand running, you can test this example with the URL http://localhost:8080/webMathematica/Examples/AJAX/LoadXML.jsp. (You may have some other URL for accessing your server.)First, this is the source of ReturnXML.jsp. This sets the content type to be text/xml, and thentakes the input number, $$num, and does an integer factorization of the factorial of the input.The result is then formatted into XML, making use of symbolic XML.num = MSPToExpression[ $$num];factors = FactorInteger[ num!];xml =XMLElement[ "factors", {},Flatten[Apply[{XMLElement["factor", {}, {ToString[#1]}],XMLElement["exponent", {}, {ToString[#2]}]} &, factors, {1}]]];ExportString[ xml, "XML"]

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

Saved successfully!

Ooh no, something went wrong!