Introduction
Many web applications use the Applet client. With this type of client, the user
accesses an Application Server through the Java Applet in the HTML document. Because
Applets restrict using files for trace output all tracing and logging for Java applets
are available through the Java console window on the browser. An alternative way
to log messages from Java applets is using Active Log application. This aticle gives
some ideas and provides online demo how to trace and log Java applets using Active
Log.
How to use the Active Log
Active Log is a Windows ActiveX application. It can be launched in Internet Explorer
browser through JavaScript by calling the ActiveXObject
object constructor:
var ActiveLog =
new ActiveXObject("VAALOG.ActiveLog");
Use the LogData method to write a message to Active Log:
ActiveLog.LogData(message,title);
Parameters
|
message |
Text message to be logged. |
|
title |
Message title that is displayed in the message list pane. |
Returns
Internet Explorer allows communication between Java Applet and JavaScript through
the Java wrapper class netscape.javascript.JSObject. In
general, applets access JSObject through the static method getWindow
which returns a JSObject representing the Window object in the JavaScript for the
window containing the given applet. This method takes java.awt.Applet
as parameter. Once this Window JSObject is obtained, the applet can call JavaScript
functions on an HTML page using call method. The Java
code below demonstrates this approach.
JSObject win = (JSObject)JSObject.getWindow(this);
win.call(String methodName, Object args[]);
Live Demo
This live demo demonstrates how Active Log can be used to log messages from Java
Applet.
Note This demo works in IE browser only.
Click Proceed To Demo to launch the demo.
Attach Active Log to Java Applet
Please follow these steps to implement this demo example:
-
Install Active Log.
- Include the jaws.jar (or plugin.jar if there's no jaws.jar) package
from the lib of the JRE in the CLASSPATH to compile demo Applet.
This is the completed Java Applet code :
- Add the mayscript attribute to the
applet tag to enable JSObject support in Java Plug-in. HTML will look like
this:
- Within the head tag of the HTML, insert the JavaScript
jsoActiveLog function used to interact with the Java Applet
and pass messages to the Active Log.
This is the completed JavaScript placed in the HTML head:
Conclusion
The Java console window already provides support for applets tracing and logging.
However, several factors make Active Log a suitable technology for logging messages
in real-time. In this article, we've covered the basics of using Active Log, and
we've seen the example of a plugging Active Log to Java Applet step by step. Many
developers and system administrators can benefit from its use.