Multiple domain web hosting - 1187Chapter 44 .Scripting Java Applets and Plug-ins catch
Wednesday, October 31st, 20071187Chapter 44 .Scripting Java Applets and Plug-ins catch (IOException e) { result = AppletError: + e; } output = result; } public String fetchText() { return output; } public void init() { } public void start() { if (thread == null) { thread = new Thread(this); thread.start(); } } public void stop() { if (thread != null) { thread.stop(); thread = null; } } public void run(){ try { getFile(fileName); } catch (IOException e) { output = AppletError: + e; } } } All the work of actually retrieving the file is performed in the getFile() method (which runs immediately after the applet loads). Notice that the name of the file to be retrieved, Bill of Rights.txt, is stored as a variable near the top of the code, making it easy to change for a recompilation, if necessary. You can also modify the applet to accept the file name as an applet parameter, specified in the HTML code. Meanwhile, the only hook that JavaScript needs is the one public method called fetchText(), which merely returns the value of the output variable, which in turn holds the file s contents. This Java source code must be compiled into a Java class file (already compiled and included on the CD-ROM as FileReader.class) and placed in the same directory as the HTML file that loads this applet. Also, no explicit pathname for the text file is supplied in the source code, so the text file is assumed to be in the same directory as the applet.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.