This is an area that I find needs exploring. Here you will find my first steps on the path to Java.
I suppose it all starts with the famous line "Hello World."
In pure Java that would look something like this:
class HelloWorld { |
The file that contains this piece of code should be named :
'HelloWorld.java'
and after compiling (using javac) you would find 'HelloWorld.class' in
the same directory.
Running it would go something like 'java HelloWorld' and the
result is a new line
printed with the famous words 'Hello World.'
This all, of course, on the command line of your terminal or DOS window.
That's all a bit useless if you want to produce those famous words on a
web page.
The way the above piece of code is written (with a 'main' body) makes
it excecutable. What
we want is make it runnable through a browser.
Okay, lets change tack.
What do we need to put in a 'html' file to make this one work.
I've created a file called, you guessed it, helloworld.html and its
content looks like
this:
<HTML> |
We need to make some changes to the original pure java because we are now implementing it as an Applet.
import java.applet.Applet; |
|
<html> <title>AJAX Server-Side Testing Script </title> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> </head> <body onload="ajaxFunctions()"> <script src="ajax.js"> </script> Server Time: <div id="time2"></div> <br> The image should change every so often. <br> <img id="RandomImg" alt=""> </body> </html> |
function ajaxFunctions(){ timeFunction(); randomImage(); } function timeFunction(){ var xmlHttp = testBrowser(); var url="/cgi-bin/ajax/..."; url = url+"? &sid="+Math.random(); xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById("time2").innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET",url,true); xmlHttp.send(null); t=setTimeout('timeFunction()', 1000); } function randomImage(){ var now = new Date(); var myimage = document.getElementById("RandomImg"); myimage.setAttribute("src", "/cgi-bin/ajax/random_image1.pl?nocache="+now.getTime()); setTimeout('getpic()', 7000); } function testBrowser() { var xmlHttp; |
Some links that might become of some interest.
Last modified:Friday, 15-Sep-2017 20:05:17 NZST