Java Applet call javascript problem

Hi I have a web page as follow and embedded a applet. The applet call the java script, and instead of showing an alarm, the browser show the javascript code. Is that strange ? Any suggestion for this problem.
HTML:
================================================================
<HTML>
     <HEAD>
     function ShowEmbd()
          alert("Test Applet call Javascript");
     </SCRIPT>
     </HEAD>
     <BODY>
     <FORM NAME="AppletEmbdStart">
          <OBJECT classid="clsid:48B2DD7B-6B52-4DB0-97C9-ECB940113B47" id="CIVON_DEmbdObj" width="0" height="0"></OBJECT>
          <APPLET code="MyApplet.class" width="0" height="0"></APPLET>
     </FORM>
     </BODY>
</HTML>MyApplet.java
=========================================================================
import netscape.javascript.*;
public class MyApplet extends javax.swing.JApplet
     private JSObject m_win = null;
     private JSObject m_doc = null;
     public void init()
          getJSWin().call("ShowEmbd", null);
     private getJSDoc()
          if(m_doc == bull)
               m_doc = (JSObject) getJSWin().getMember("document");
          return m_doc;
     private JSObject getJSWin()
          if (m_win == null)
               m_win = netscape.javascript.JSObject.getWindow(this);
          return m_win;
}The page was load and it should call the applet MyApplet. The MyApplet should do the init() method and call the Javascript "ShowEmbd()", BUT, instead of show alert from ShowEmbd(), the browser show the code of ShowEmbd() itself ...... It did not run the javascript and shows the alert ??
The browser shows a message from status bar "The applet not initial" ???? why ???
Can anyone help ?!

On first look:
I am not sure about the Object Tag, but the Applet Tag requires the MAYSCRIPT attribute before Java can call Javascript.

Similar Messages

  • Java Applet to Javascript Communication

    There is a Java Applet which digitally signs files after taking
    private key from a smart card.This applet takes external files.
    I want to do this "Generate digital signature of a web page with the
    help of an applet of which the applet is itself a part"
    I am trying using Java Applet to Javascript Communication.
    I am able to access the object which represents the HTML document.
    That abject is represented by document itself.
    Now I have to somehow generate the whole webpage i.e. like we view in a
    notepad like this:
    <HTML>
    <Title>my page</title>
    Then write into a file and then that file can be signed.
    This is what I feel.
    In C#.net there is a method .innerhtml.
    Does such kind of a method exists in Java.???
    I m searching but cudn't get till now.
    Will serialization work??

    Kindly forget the previous post. Read the following:
    JSObject browserWindow = JSObject.getWindow(this);
    JSObject doc = (JSObject)browserWindow.getMember("document");
    Here doc represents the object of the HTML document.
    This is accessed using Java Applet JavaScript Communication.
    I want to serialize the object represented by doc.
    Then write it into a file and generate it's digital signature.
    In the below written line the parameter fileName is passed.
    CertificationChainAndSignatureBase64 signingResult = signFile(fileName);
    For this I have added few lines in the code written below.
    see first 10-30 lines. Though this code gets compiled but it is not running. When I want to sign the file , it throws an error
    "Unexpected error:sun.plugin.javascript.ocx.JSObject"
    This code is just one class. Two other classes are needed to completely test the code.
    Should I post them ??
    Kindly see what is the error.
    I will be highly grateful and Sorry for confusing in the previous mail...
    private void signSelectedFile() {
    try {
    // Get the file name to be signed from the form in the HTML document
    JSObject browserWindow = JSObject.getWindow(this);
    JSObject mainForm = (JSObject) browserWindow.eval("document.forms[0]");
    String fileNameFieldName = this.getParameter(FILE_NAME_FIELD_PARAM);
    JSObject fileNameField = (JSObject) mainForm.getMember(fileNameFieldName);
    //This is another modification
    //String fileName = (String) fileNameField.getMember("value");
                   //here we get the document......
    JSObject doc = (JSObject)browserWindow.getMember("document");
    //String docum = doc.toString();
    String thePage = "as";
                   FileOutputStream out = new FileOutputStream(thePage);
                   ObjectOutputStream s = new ObjectOutputStream(out);
                   s.writeObject(doc);
                   String fileName = thePage;
                   JOptionPane.showMessageDialog(this, fileName); //"Unexpected error: " + e.getMessage());
    // Perform the actual file signing
    CertificationChainAndSignatureBase64 signingResult = signFile(fileName);
    if (signingResult != null) {
    // Document signed. Fill the certificate and signature fields
    String certChainFieldName = this.getParameter(CERT_CHAIN_FIELD_PARAM);
    JSObject certChainField = (JSObject) mainForm.getMember(certChainFieldName);
    certChainField.setMember("value", signingResult.mCertificationChain);
    String signatureFieldName = this.getParameter(SIGNATURE_FIELD_PARAM);
    JSObject signatureField = (JSObject) mainForm.getMember(signatureFieldName);
    signatureField.setMember("value", signingResult.mSignature);
    } else {
    // User canceled signing
    catch (DocumentSignException dse) {
    // Document signing failed. Display error message
    String errorMessage = dse.getMessage();
    JOptionPane.showMessageDialog(this, errorMessage);
    catch (SecurityException se) {
    se.printStackTrace();
    JOptionPane.showMessageDialog(this,
    "Unable to access the local file system.\n" +
    "This applet should be started with full security permissions.\n" +
    "Please accept to trust this applet when the Java Plug-In ask you.");
    catch (JSException jse) {
    jse.printStackTrace();
    JOptionPane.showMessageDialog(this,
    "Unable to access some of the fields of the\n" +
    "HTML form. Please check the applet parameters.");
    catch (Exception e) {
    e.printStackTrace();
    JOptionPane.showMessageDialog(this, "Unexpected error: " + e.getMessage());
    }

  • Java Applet vs JavaScript

    Trying to find pros and cons for Applet and JavaScript. Anyone know any or a good place to look?
    Thanks

    I suppose it depends on what you ultimately want to see. In many ways (many) JavaScript and Applets are not comparable. And you can use Javascript with Applets and vice versa. I have a web application I work on that uses lots of JS with DHTML and it also communicates with an applet, and the applet calls JS stuff as well.
    Trying to use JS/DHMTL for very complex GUIs is going to be slower performance then an applet, but probably faster download/start time. Applets also should be using the Java Plug-in which the user would have to pre-install. Netscape 7 has no built-in JVM anymore, and the built-in ones in Netscape 4.7 and IE are both old (JDK 1.8) and buggy.
    I agree with your advantages. As for the disadvantages:
    1. For non-programmers learning curve can be steep.Who is the target user? A developer? The client browser user wouldn't care about this.
    2. Not standard support for Javascript across browsers esp. DOMYes, however, if you can restrict people to IE6 and Netscape 7, then you will find that the differences are minimal. Nothing at all like the difference between them and Netscape 4.7. I'm not up on the latest Opera's support, however.
    3. Web page useless if script does not work!!"does not work" sounds like a development problem. Good, correct code will work.
    4. Javascript may be disabled by browser reading HTML file no control over thisYes, but if you A) have proper checking you can be sure it's enabled, and B) applets can also be enabled.
    5. Anyone can see the JavaScript source code by viewing the
    HTML document source. Thus you could not create a secure
    multiple-choice test in JavaScript; it would be very easy to
    see the answers!While this is generally true, you can do some tricks to solve that type of problem. Lets take this example. You can find Javascript code for creating MD5 hashes, and you can then use that to store the hash of the answers in the page and use the MD5 code to compare the given answers to the real ones. This type of thing is not good for all, of course.
    6.Even though JavaScript is a standard, different browsers
    interpret JavaScript differently, and some commands that work
    fine on one browser simply do not work on another. You must
    carefully test your JavaScript code on all browsers to make
    sure it runs correctly.This is basically the same type of problem as #2 above, and I would give the same answer. Ultimately, you have to limit yourself to certain browsers/versions. But if the user wants to see it, there's little you can do.
    As Sue said, Flash is pretty robust and more secure, since it's easy enough to decompile applets. And server side things would be better security as well, if that's a big issue.

  • Applet calling javascript function causing memory leak

    Hi,
    I'm troubleshooting one memory leak issue in my application and to do that I created one simple Java applet and HTML + javascript function to locate the problem.
    Basically it's an applet calling a javascript function using a timer. The javascript function simply does nothing.
    I tested in IE 8.0 and JRE 1.6.0_23-b05 and memory of IE keeps increasing.
    I saw this bug http://bugs.sun.com/view_bug.do?bug_id=6857340 which seems related with my issue, but if I understand correctly from the page, the issue should have been fixed.
    I posted this message to find out if others also find same issue and if there's a solution for this. If I comment out window.call("dummy", null); , memory will not climb up.
    Java code
    +public class Main extends Applet implements Runnable  {+
    public Applet currentApplet= this ;
    +     public JSObject window = null;+
    +public void run(){+
    +          System.out.println("run..");+
    +     }+
    +public void start(){+
    window = JSObject.getWindow(this);
    int delay = 300; //milliseconds
    +ActionListener taskPerformer = new ActionListener() {+
    +public void actionPerformed(ActionEvent evt) {+
    window.call("dummy", null);
    +}+
    +};+
    new Timer(delay, taskPerformer).start();
    +     }+
    +public static void main(String[] args) {+
    +          System.out.println("start...");+
    +          Main main = new Main();+
    +     main.start();+
    +     }+
    +}+
    Javascript source code
    +<html>+
    +<head>+
    +<script>+
    +function dummy() {+
    +     +
    +}+
    +</script>+
    +</head>+
    +<body>+
    +<applet .... >+
    +...+
    +</html>+

    Try this url:
    http://www.inquiry.com/techtips/java_pro/10MinuteSolutions/callingJavaScript.asp
    It also provides some examples.

  • When Java applet invokes JavaScript which executes window.showModalDialog, get popup with about:blank

    When using a Java applet that invokes a Javascript function that in turn calls window.showModalDialog, a pop-up dialog that only contains "about:blank" results. Selecting "show desktop" from the Windows 7 taskbar and then viewing the FireFox window results in the true dialog content being displayed. Everything worked properly until very recently (and old versions of FireFox work) and I suspect something was changed in FireFox as a result of the recent Java security failures.

    Hello, I don't know about this specifically but this is what I would try.
    Instead of the string "\u7834\u70C2\u7269\u7A0B\u5E8F\u5458..."
    Set the encoding type in the String constructor first...
    ie:
    new String( "\u7834\u70C2\u7269\u7A0B\u5E8F\u5458...","GB18030");
    Here is a little class I whipped up to show the CharSets that are available to you..
    public class ShowAllCharSets
    ShowAllCharSets()
    Map myMap = Charset.availableCharsets();
    Iterator iterator = myMap.keySet().iterator();
       while (iterator.hasNext())
          System.out.println("Char set name = "+((String)it.next()));
    public static void main(String args[])
       new ShowAllCharSets();
    }Then use the preset charset String with the specific encoding already set for your menu items.
    GB18030 I picked arbitrarily because it is Chinese and you may have to try another.
    Good Luck!
    (T)

  • Java Applet Background Color Problem on Internet Explorer

    Hi,
    Please check out the following URL:
    http://www.utopiainteractive.com/clients/AkonFinal/glossary.htm
    The menu bar is writting in Java Applet. If you scroll down the page, and scroll back up, I see white background as I scroll back up. It happens only on Internet explorer. Neither Java Applet nor HTML Body bg color is white. I am kinda lost, and any help would really be appreciated.
    Thank you and look forward to hearing from someone soon.
    Sachin

    Hi,
    Well I used HtmlConver utility to generate applet html code, so I assume nothing is wrong with Object tag. Do you know what could cause this problem on Internet explorer? To be honest, I spent last couple of days, but I am just lost. It absolutely works fine on Netscape.
    Thanks,
    Sachin

  • Can Java Applet Call the ASP Page

    Hi,
    I would like to know whether the Java Applet can call the ASP page.
    If it can be done, how does the Java Applet get the value from ASP page?
    Please provide me some running example.
    Thanks.

    I would like to know whether the Java Applet can
    an call the ASP page.Something like:
    AppletContext.showDocument(new URL("http://wherever/myPage.asp"), "_blank");
    how does the Java Applet get the value from ASP page?What?
    Please provide me some running example.Nope.

  • How to Debug Java Applet called in a BSP Component

    Hi All,
    In CRM Marketing->Segments->Graphical Modeler
    A click on settings button will load a Java Applet window.
    The settings window displays some elements. I want to translate a text displayed in that Java Applet window.
    Please let me know the ways to debug a Java applet loaded from BSP Component or ways the data is loaded into Java applet from SAP.
    Your help would be appreciated and points will be rewarded.
    Thanks a lot in advance.

    For the newbies, like me:
    Instruction to setup and debug an applet in Eclipse IDE via your Browser
    Java Console Setup for Applet debugging:
    1. Open up the Java Console Application by double clicking on it at C:\Program Files (x86)\Java\jre1.6.0_03\bin\javacpl.exe
    2. Select the Java Tab
    3. View Applet Runtime Settings button
    4. Enter in the Java Runtime Parameters the following: -Xdebug -Xrunjdwp:transport=dt_socket,address=5555,server=y,suspend=y
    5. Note: the port address 5555 can be anytime you want. You will need to enter whatever number you select into Eclipse IDE.
    6. Note: if you don�t need to debug code in the Applet�s init() method, then use....suspend=n (Not tested yet.)
    Eclipse setup for Applet debugging:
    1. Open up Eclipse and create your Applet. Once you are ready to debug go to the next step.
    2. Select the top level Run menu
    3. Pick the Open Debug Dialog� option
    4. In the left column select Remote Java Application
    5. Then select the �New� button to create a debug configuration for the remote session (the new button looks like a page with a yellow plus in the upper right hand corner)
    6. Give your session a name. I used the class name followed with the work remote for example: mainclassnameRemote
    7. Set connection type to Standard (Socket Attached)
    8. Host to localhost
    9. Port to 5555, or whatever you used in Java Console Setup step 5.
    10. Due not check the �Allow termination of remote VM�
    11. Due not close this window.
    Start debugging:
    1. Go to your Applet html launch file and launch in a browser
    2. Then go back to eclipse and select the debug button
    3. Eclipse should now throw you into the debugger mode.
    4. If it hangs, just retry again. It seems to work ok most of the time. A few time I need to close the browser and start over and then it seems to work.

  • Java applet calling another applet on the Javacard

    Hi, I am new to JC.
    I have some Java classes which I do not want others to extend. Hence, to hide these classes, I have created a set of helper classes that will provide services to these "hidden" Java classes to other calling applets, much like the way I do in J2SE. Something like a wrapper class.
    The problem is, I am not sure if other applet classes can call this new helper class or not? and I am also not sure how this can be done. Can someone advise? Thanks in advance.

    I'm not sure what this has to do with JavaCards.
    Sounds like a simple Facade Design Pattern. Also your classes are "hidden" when you make them package protected or package private. Read J2SE packages and you'll see what I mean.
    If you are referring to JavaCard, by design each package is it's own context therefore, there's a context firewall to protect it's objects and data. A shareable Interface object must be implemented to allow access.

  • Java Applet re-creation problem

    Hi skilled,
    At our project we use an Applet that resides in the iFrame. On the main page the iFrame is used to show an Applet.
    There is a table with two cells, there is DIV in every cell with IDs �div1� and �div2� accordingly. The iFrame is in the "div1".
    When we move an iFrame from �div1� to �div2� using the JavaScript code below:
    div2.appendChild(
    document.getElementById('myframe')
    where �myframe� is the iFrame ID, the Applet destroys and new one is being created. This leads to the loss of data that was stored in the applet before.
    We need to avoid such a behavior of the Applet somehow or find a workaround to this problem.
    This problem reproduces on SUN JVM 1.5.0.11 and 1.6.0.x.
    Please share your ideas/suggestions with me � you will help us a lot.

    I can save the data from the old applet when it is going to destroy, however I cannot pass it to the new one.
    Here is the problem:
    - until the <iframe/> is moved, my browser has a right reference to the applet - I can use any public methods of an applet;
    - then, I move an <iframe/> tag to another cell/div, JVM destroys my applet and creates a new one, however the browser have lost the reference (or it holds the reference to the old applet which is destroyed) - so, I cannot call any applet method from JavaScript anymore.
    And one more thing, when applet is being recreated in this way, it is no longer re-draws itselft. Update and Paint methods are no longer called inside an applet even if to call them by hand (repaint function).
    Btw, this is not reproduces on MS JVM :) That's strange problem...
    Any help will be really appreciated.
    Thanks,

  • How do I integrate Java Applet and JavaScript?

    Hi:
    This has been asked before, I have read the archives, yet I'm still left with some doubts, and some posts are VERY old and may not apply today. (sorry, some questions might seem stupid, this is my first applet). The purpose is to create a light weight application for managing certificates stored on a smart card, requesting certificate renewal from a server and installing the issued certificate on the card.
    I need to create an applet (signed) to bridge the gab caused by the security limitations of JavaScript in order to access the smart card on the client. The applet will manage certificates on the card and do client-card interaction, while all client-server and user interaction is done by AJAX/JavaScript.
    So, the applet is actually supposed to be an invisible object embedded on the page that is accessed by the JavaScript. How do I go about this?
    - is there any reason to prefer JApplet over Applet?
    - do the JavaScript need to invoke start() or init() or is this done on page load?
    - are there limitations on data exchange with the applet (ie. only string types)?
    - how do I throw exceptions from the applet to the calling script?
    and: will is it better to let JavaScript do all http to keep the applet light, or to let the applet fetch files given a URL (to fetch the new certificate)?
    If the applet is stored in a jar-file, how do I indicate which class/method to invoke? Do the JavaScript have access to public methods only?
    Thanks for your advice and suggestions,
    Erik

    Hi,
    Are you still interested?
    I can work with you over this.
    Adil

  • Java applet called WebEQ doesnt work properly

    hi there... its been sometime now since i started using WebEQ on some sites i'm signed in... this java appler allow to see math equeations on the web...
    until firefox4 every thing was o.k.
    now i cant never see the first object on the page...
    look at the exampels...
    http://imageshack.us/photo/my-images/151/69134815.png

    if (e.getKeyCode () == e.VK_DOWN) <----THIS
    --THIS SECTION
    b= b+2;
    for (int o = 1 ; o < 60 ; o++)
    repaint ();
    if i get your question corectly, shouldn't b=b+2 be in the for loop not outside it

  • In a java applet , how to call other jar file?

    i have i programm, this programm is a java application,
    also, i already put these program into jar file, and then if i double this jar file , its work!
    but , now i need to run this program in web browser,
    i thing that i will write a simple applet with a button
    after i click this jButton, how the java applet call and run the java file?
    please help me.. it is because this is my project! thx..........
    [email protected]

    I have a solution write one batch file in that you specify class path and java home.
    then give
    java -jar Test.jar
    then call this batch file from program using Java runtime
    Runtime.exec method...
    Hope will this work

  • Problem running Java applets since Java update 2 (1.6.0_20)

    Hi,
    Since I upgraded to Java update 2, Java applets started having problems. The most noticeable ones are:
    Non-modal windows appear behing the browser Window (tested Safari 4, 5, Chrome 5).
    Double buffering not working as usual (slower, white boxes appear when dragging a window, etc.)
    Slower rendering in general
    The same applications run perfectly using Java Web Start. And they used to work very well also in Java update 1.
    The application can be tested here (press ok if a login prompt appears):
    Java applet: http://jmap3.k2geospatial.com/montreal_applet/
    Java Web Start: http://jmap3.k2geospatial.com/montreal_jws/dockingClient.jnlp
    Our applications running in applets use the new plug-in 2 with JNLP files.
    Notice the Java startup splash (the animated sun-like logo) is not moving as smoothly as usual. It is very jerky now.
    Are these problems known by anyone?
    How can I downgrade Java to previous version?
    sorry I cross-posted this in Unix forum also. I think it is better here.
    Thank you,
    Jean-Robert
    K2 Geospatial

    Since the last Java update on mac, all my OpenGL applets stop working and now just shows a white screen on Chrome, Firefox and Opera. They was working well on all browsers (Safari/WebKit,Chrome,Firefox,Opera) just before the update.
    The trouble maker seem to be the java plugin 2 and the new offscreen rendering pipeline, as reported by jrhaddad with the disucssion linked to the different Java/OpenGL community forums.
    This is a huge regression for me, and I think for all hobbies/ independent developers and all companies who are doing some Java/OpenGL develoment. All our work just stop working since this update.
    If would really want to know from Apple if they are working on this problem and/or how this can be solved.
    Should this be fixed by Apple with a new java update, or should the various browsers must upgrade their applet support plugins according to the new java plugin 2 changes ?
    Best Regards,
    Jérôme

  • Run Priviliged Code in a Java Applet

    I am calling a Java applet from Javascript. The Java code needs to run in privileged mode.  Eventually it is going to display a file chooser which will display files from the local hard disk, but for now it just returns a simple dummy value.  The problem I am having is that the call from JavaScript to Java returns PrivilegedActionException. The applet is in a signed Jar file.  I'm running 8u25.
    Here's the Java class:
        // Java code
        public class OHLib extends Applet {
            public String getFile() {
                String result;
                try {
                    result = (String) AccessController.doPrivileged(new PrivilegedAction() {
                        public String run() {
                            // JFileChooser code will go here
                            return "xxx";
                } catch (Exception e) {
                    e.printStackTrace();
                return result;
    Can anybody tell me what's wrong with this code?  I would also be interested to know why the above try/catch block is not catching the exception.  The only place I see the exception is in the browser F12 developer tools.
    Here's the JavaScript code:
        function BrowseForFile() {
            var x;
            try {
                 // this code generates PrivilegedActionException
                 x = ohApplet.getFile();
            } catch (e) {
                 console.log(e);
    The applet is deployed on my web page as follows:
    <script src="/plugins/deployJava.js"></script>
    <script>
         var attributes = {
             id:'ohApplet',
             code:'OHLib',
             codebase: 'java',
             archive: 'OHLib.jar',
             width:1,
             height:1,
         var parameters = {
          jnlp_href: 'OHLib.jnlp',
          classloader_cache: 'false',
         deployJava.runApplet(attributes, parameters, '1.8');
    <script>
    The applet is in a signed jar file, with the following manifest:
    Application-Name: <appname>
    Permissions: all-permissions
    Codebase: <domain>.dev <domain>.com
    Caller-Allowable-Codebase: <domain>.dev <domain>.com
    Application-Library-Allowable-Codebase: <domain>.dev <domain>.com
    The JNLP file is as follows:
        <?xml version="1.0" encoding="UTF-8"?>
        <jnlp spec="1.0+" codebase="" href="">
            <information>
                <title>title</title>
                <vendor>vendor</vendor>
            </information>
            <security>
                <all-permissions />
            </security>
            <resources>
                <j2se version="1.8+" href="http://java.sun.com/products/autodl/j2se" />
                <jar href="OHLib.jar" main="true" />
            </resources>
            <applet-desc
                 main-class="OHLib"
                 name="OHLib"
                 width="1"
                 height="1">
             </applet-desc>
        </jnlp>       

    The problem was that I was not including the anonymous inner class (OHLib$1.class) in the jar file. My original jar command looked like this:
    jar cfmv OHLib.jar "../../jar_manifest.txt" OHLib.class
    Changing it to below fixed the problem:
    jar cfmv OHLib.jar "../../jar_manifest.txt" OHLib.class OHLib$1.class
    Credits go to this page  for the solution.

Maybe you are looking for