开发者

how to call a java function from javascript?

开发者 https://www.devze.com 2023-01-24 05:27 出处:网络
I\'ve seen many tutorials, but none of them have worked in my case, I think it is because I\'m using a .jar instead of an .class and in that .jar, I have more than just one Java class.

I've seen many tutorials, but none of them have worked in my case, I think it is because I'm using a .jar instead of an .class and in that .jar, I have more than just one Java class. Anyone knows how to sol开发者_开发技巧ve this?

code: http://dl.dropbox.com/u/1430071/code.txt


Ignore the DWR answers, they misunderstood your architecture. Applet code runs on client, not server.

What error message do you get?

Is the method you are trying to call public?

The way you are calling the Java method, the method has to be in the applet class. Is it?

It seems like your applet tag is missing the code attribute. It's required. Quoting an example from Oracle:

  <applet codebase="http://java.sun.com/applets/NervousText/1.1"
    code="NervousText.class" width=400 height=75>
  <param name="text" value="Welcome to HotJava!">
  <hr>
  If you were using a Java-enabled browser such as HotJava,
  you would see dancing text instead of this paragraph.
  <hr>
  </applet>

The code attribute must reference an applet class (a class that extends java.awt.Applet or javax.swing.JApplet) that can be found in one of the jars you've listed in the archive attribute. This has to be the full name of the class, something like: my.package.MyApplet (the .class at the end is optional).


Are you trying to call server side java from client side javascript? You would need to wire up a DWR call.


As Joe mentioned, DWR can help you here. Here a link to their tutorials.

0

精彩评论

暂无评论...
验证码 换一张
取 消