File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call java method from javascript when using java plug-in

 
arul narayan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to call java method from javascript when i use the browser's JVM.
But when i use the java plug-in, and call the java method, I get:"error:document.myApplet not an object". How do I call the java method in this case?
Given below is the code snippet for better understanding of the problem or to find out whether I am missing something here. Thanks.
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "0" HEIGHT = "0" codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1.2.2-win32.cab#Version=1,2,2,0">
<PARAM NAME="code" VALUE="HelloWorld.class">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="name" VALUE="myApplet">
<PARAM NAME="scriptable" VALUE="true">
</OBJECT>
<input name=Submit type=submit value="test" onClick=document.myApplet.callMethod()>
</p>
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I am aware, this is not possible. I needed to do it some months ago, and wrote some diagnostic JavaScript to traverse the whole JavaScript object tree, and did not find any mention of my applet.
Applets in a Plug-in can call JavaScript, but the reverse seems just not possible. In the end I had to make my applet sit in a thread, waiting and polling a JavaScript variable until the JavaScript set it.
 
xavier gagneur
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Carver:
As far as I am aware, this is not possible. I needed to do it some months ago, and wrote some diagnostic JavaScript to traverse the whole JavaScript object tree, and did not find any mention of my applet.
Applets in a Plug-in can call JavaScript, but the reverse seems just not possible. In the end I had to make my applet sit in a thread, waiting and polling a JavaScript variable until the JavaScript set it.

Hi,
I can call Java Methode in Applet using plug-in but I can't Call Javascript from Java.
That is my problem! Just see that...
///////////////////
//HTML SOURCE
<html>
<HEAD>
<SCRIPT code="JavaScript">
function writeHtml(nbr){
document.writehtml.writeHtml(nbr);
};
</SCRIPT>
</HEAD>
<BODY>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="300" height="300" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win.cab#Version=1,3,0,0"
name="writehtml">
<PARAM NAME=CODE VALUE=HtmlWriter>
<PARAM NAME="codebase" VALUE=".">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="true">
<PARAM NAME="MAYSCRIPT" VALUE="true">
</OBJECT>
<FORM name="resto">
Nombre de lignes a g�n�rer : <input name="result" type="text" value="5"><BR>
<input type="button" onclick="javasript:writeHtml(document.resto.result.value)" value="OK">
</FORM>
</BODY>
</HTML>
//////////////////////
//JAVA JAPPLET SOURCE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import netscape.javascript.*;
public class HtmlWriter extends JApplet{
JSObject win = null;
public void paint(Graphics g){
g.setColor(Color.black);
g.drawString("APPLET RUN...", 15,35);
}

public void writeHtml(String Nombre){
win.eval("alert('TEST2');"); // CRASH HERE!!!
}
public void init(){
win = JSObject.getWindow(this); //OK
win.eval("alert('TEST');"); //No PROBLEMES HERE
repaint();
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic