开发者

JSP - JS - Java interaction

I am trying to call a method in a Java applet from JS. I am a little bit confused about how to arrange my workflow. I have a jsp (pending.jsp) class which includes a javascript (pending.js). pendin开发者_C百科g.jsp is just a container to hold pending.js. pending.js' purpose is to enable users to cancel report creation.

pending.jsp:

<div id="pending-reports-container" class="pending-reports-container">

    <div id="pending-reports">

    </div>
</div>

pending.js:

function update_pending_reports(response_data)
{ bla }
function delete_report(report_id)
{ bla }
function request_pending_reports()
{ bla }
function start_pending_reports() {
    request_pending_reports();
    setInterval("request_pending_reports()", 5000);
}

Because cancelling reports sometimes is not that efficient I want to use Java to cancel requests that goes to the postgres (pending.js does not kill the process that works at postgres). I created my Java class but I don't know where to add it. I know I can make use of tag, but when I tried to add this tag to my jsp file like this:

<div id="pending-reports-container" class="pending-reports-container">

    <div id="pending-reports">
       <applet id="LS" width=1 height=1 code ="module/LicenseCheckService.class" codebase="."/>
    </div>
</div>

I can not reach it from my pending.js with this code:

 getJS = document.getElementById("LS");

Is there something wrong with my code or am I wrong at this structure in the first place?


See the Invoking Applet Methods From JavaScript Code Oracle docs.

Nutshell version is that the JavaScript refers to the applet object by the applet ID, and can call methods on it.

appletId.anAppletMethod();
var anAppletClass = appletId.getAnAppletClass();
anAppletClass.methodCalled("with a JavaScript string parameter");
// Etc.


See Dave Newton's answer.

Alternatively, you can also check the HTML field or call a javascript method from Applet. You can construct the interaction to be actively controlled by the applet.

Link here : Java Applet To JS Link

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜