53
import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;
public class TextApplet extends Applet
{
public void paint(Graphics g)
{
super.paint(g);
try {
URL url=new
URL(getDocumentBase(),getParameter("ArgumentURL"));
InputStream in=url.openStream();
ByteArrayOutputStream out=new ByteArrayOutputStream();
byte[] b=new byte[1024]; int len;
while((len=in.read(b,0,1024)) != 1) {
out.write(b,0,len);
}
b=out.toByteArray();
g.drawBytes(b,0,b.length 1,20,20);
}
catch (Exception e) {
System.out.println("Error "+e);
}
}
}
This is a very simple applet; the paint method opens a connection to a URL, the name of which is formed from the
document that loaded the applet, and the value of the parameter ArgumentURL, which is passed in from a param
tag. This causes the TextApplet JSP to be called and return a computation of the date.
3.10 JavaScript: PlotScript.jsp
This example demonstrates how to integrate a Mathematica powered web site with JavaScript. It also demonstrates
both client and server programming. The section involves some programming in JavaScript.
Note that JavaScript and Java are different languages. JavaScript is a scripting language that is useful for manipulat
ing documents and other features of browsers. Java is a general purpose programming language that can be used in
an HTML document via an applet. The two languages complement each other; JavaScript is useful for manipulating
the browser and documents that are open in the browser, while Java has a more sophisticated collection of functions
and can draw into the browser window. It is possible for JavaScript and Java to work together.
If you installed webMathematica as described
above
, you should be able to connect to this MSP via
http://localhost:8080/webMathematica/Examples/PlotScript.jsp. (You may have some other URL for accessing your
server.) The source for this page is in webMathematica/Examples/PlotScript.jsp and web
Mathematica/Examples/PlotScript1.jsp.
First, here is the source for PlotScript.jsp.
.
<
New Page 1
Comcast Web Hosting