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

Similar Messages

  • 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.

  • How can we  use java variable in javascript code on JSP page?

    How can we use java variable in javascript code on JSP page?
    Pls help

    Think about it:
    JSP/Java is executed on the Server and produces HTML+JavaScript.
    Then that HTML+JavaScript is transfered to the client. The client now interpretes the HTML+JavaScript.
    Obviously there's no way to access a Java variable directly from JavaScript.
    What you can do, however, is write out some JavaScript that creates a JavaScript variable containing the value of your Java variable.

  • 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());
    }

  • How to sign a java applet using iPlanet SSL certificate?

    Dear all,
    I have a IPlanet web server with SSL installed,
    can I use the SSL certificate to sign my java applet which will run on the server? how to sign a java applet in this scenario? somebody please help me! thanks!
    yours sincerely
    dashel

    Why can't you create jar files?

  • Difference between Java applet and JavaFX

    Hello, all!
    I am studying javaFX in general. As far as I understand there is no main difference between java applet and javafx, except javafx has different syntax and library simple to use. Is it right?

    Basically, yes. But as you point out, it is supposed to be faster to develop in JavaFX...
    For example, Processing allows to export to applet, and is strong on doing graphics, but to see if user has clicked on a circle, you have to check the mouse coordinates against the circle coordinates, or create your own Circle class: it is at a much lower level.
    Likewise, you can use gaming frameworks like Slick2D or PulpCore, but they might be lacking on GUI (but perhaps faster). Or use Apache's Pivot, strong on GUI, but perhaps lacking a bit on graphics and animation.
    It depends on your needs, if you prefer to stick to Java, etc.

  • How is the length of a string calculated in Java?  and JavaScript?

    Hi all,
    Do any of you know how the length of a string is being calculated in Java and JavaScript? For example, a regular char is just counted as 1 char, but sometimes other chars such as CR, LF, and CR LF are counted as two. I know there are differences in the way Java and JavaScript calculate the length of a string, but I can't find any sort of "rules" on those anywhere online.
    Thanks,
    Yim

    What's Unicode 4 got to do with it? 1 characteris 1
    character is 1 character.
    strings now contain (and Java chars also) is
    UTF-16 code units rather than Unicode characters
    or
    code points. Unicode characters outside the BMPare
    encoded in Java as two or more code units. So it would seem that in some cases, a single
    "character" on the screen, will require two charsto
    represent it.So... you're saying that String.length() doesn't
    account for that? That sux. I don't know. I'm just making infrerences (==WAGs) based on what DrClap said.
    I assume it would return the number of chars in the array, rather than the number of symbols (glyphs?) this translates into. But I might have it bass ackwards.

  • How to access a file via Applet and JavaScript

    I want to copy one file on the client machine from one place to another place from a Java Bean.
    To do this I created an applet and a Java Bean as follows:
    import java.applet.*;
    public class FileUtils extends Applet {
        public void copyFile(String src, String dest)  {
        private String source, destination; // setters/getters are there of course
        public void copyFile(ActionEvent actionEvent) { // Bean
            FacesContext fctx = FacesContext.getCurrentInstance();
            ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
            String command = "var s = '"+ source +"'; var d ='" + destination +"'; " +  " document.fileUtilsApplet.copyFile(s, d); ";
            erks.addScript(fctx, command);
        }Then I added the APPLET tag referencing the above class in the page fragment:
                    <f:verbatim>
                        <applet code="FileUtils.class" name="fileUtilsApplet" height="30"
                                archive="/context-root/Applet.jar"
                                width="200">
                        </applet>
                    </f:verbatim>From the Java console I can see the jar is successfully downloaded, but when the code in the bean is executed, the JavaScript code does not seem to do anything, as if the "copyFile" public method was not called at all and no output in the Java Console as well.
    Note that I already followed the guidelines at http://www.oracle.com/technetwork/developer-tools/adf/learnmore/71-adf-to-applet-communication-307672.pdf .
    Do you have any ideas?

    Ok, I can see the permission problem now:
    java.security.AccessControlException: access denied (java.io.FilePermission c:\myfile.txt read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
    Edited by: user10047839 on 1-feb-2013 7.29
    signing the Jar and downloading the certificate permanently does not change anything in Firefox. The Java console keeps giving the above exception.
    Any idea?

  • How can I enable java applet plug-in and Web Start applications via terminal?

    Since the last Java update to Snow Leopard, I have found that the system periodically disables the Java applet plug-in after a period of disuse.  I know I can go to /Applications/Utilities/Java Preferences and just click to re-enable Java.  But I want to write a script which will do this periodically for a couple hundred Mac users where I work. 
    My question is - how can I reenable the Java applet plug-in and web start applications via Terminal command?  Is this possible?  Is there a plist file that can be modified, etc.?
    Bob Reed

    It is my understanding that Apple's most recent Java update automatically disables Java after a certain period of time that it hasn't been used.  We don't want users to have to keep re-enabling it.  So we wanted to find a way to do this via script either run by a Casper JSS server or stored locally on each workstation.   With the guidance provided by Mark Jalbert above and some text from a script written by Rich Trouton, I was able to make a script (with some minor changes) and a launch agent to re-run the script upon login.  So the preference is always enabled.
    For your reference, the script content is:
    #!/bin/sh
    # DYNAMICALLY SET THE UUID FOR THE BYHOST FILE NAMING
    if [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` == "00000000-0000-1000-8000-" ]]; then
    MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c51-62 | awk {'print tolower()'}`
    elif [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` != "00000000-0000-1000-8000-" ]]; then
    MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62`
    fi
    # Set the the "Enable applet plug-in and Web Start Applications" setting in the Java Preferences for the current user.
    /usr/libexec/PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsEnabled" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UU ID}.plist
    /usr/libexec/PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsEnabled bool true" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UU ID}.plist
    /usr/libexec/PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsLastUsed" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UU ID}.plist
    /usr/libexec/PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsLastUsed real $(( $(date "+%s") - 978307200 ))" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UU ID}.plist
    The launch agent plist content is:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
              <key>Disabled</key>
              <false/>
              <key>Label</key>
              <string>org.XXXXX.enableJavaPlugin</string>
              <key>ProgramArguments</key>
              <array>
                        <string>sh</string>
                        <string>/Library/Scripts/XXXXX/enableJava_plugin.sh</string>
              </array>
              <key>RunAtLoad</key>
              <true/>
              <key>StartOnMount</key>
              <true/>
    </dict>
    </plist>
    I hope this is helpful to anyone wishing to keep the Java web plugin enabled.
    Bob
    Message was edited by: Robert Reed2

  • Problem with java applet and array of arrays

    hi!
    i'm passing an array of arrays from java applet using
    JSObject.getWindow(applet).call("jsFunction", array(array(), array()) );
    in every other browser than safari 4.0.2 it's no problem to iterate over this array. in safari "array.length" is undefined. is such construction supported in safari's js engine?
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl

    Thanks for the answer but the problem is the type of object of method and how from pl/sql is posiblle to call.
    The method waiting a ArrayofAlicIva, but if i define this object is not posible to set the object inside the array because the wsdl not have this functions.
    I need to define array of objects but the object is inside is the diferent type of array.
    If i Define the array of object correct to object inside, the method expect that the other array type.
    Is a Deadlock ??
    The solution in Java is Simple
    AlicIva[] alicIva = new AlicIva[1];
    alicIva[0]= new AlicIva();
    alicIva[0].setId(Short.parseShort(1));
    fedr[0].setIva(alicIva);
    this is the method imported in java class to form
    -- Method: setIva (LArrayOfAlicIva;)V
    PROCEDURE setIva(
    obj ORA_JAVA.JOBJECT,
    a0 ORA_JAVA.JOBJECT) IS
    BEGIN
    args := JNI.CREATE_ARG_LIST(1);
    JNI.ADD_OBJECT_ARG(args, a0, 'ArrayOfAlicIva');
    JNI.CALL_VOID_METHOD(FALSE, obj, 'FECAEDetRequest', 'setIva', '(LArrayOfAlicIva;)V', args);
    END;

  • 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.

  • How to put my java applet application inside a browser

    currently I have a java applet appilcation but it pops-out outside the browser. does anyone can show me how to embed it on my browser

    make an html file like this inside the same folder as your .class files
    <html>
    <body>
    <p align = center><applet code ="Main.class" width=500 height=300>
    </applet></p>
    </body>
    </html>width and height have to be within the resolution of your screen

  • 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 Applets and Packages

    Hi
    I have been having problems calling my own packages in java applets to no avail
    For a basic example i am storing graphics in a package called graphics and i have a class with a drawline function.
    How would i call this in my main program?
    At the top of the code i have imported the correct package using import useful.oh;
    I have tried the "oh oh = new oh();" which does not cause any compile errors however it doesnt result in a line on screen.
    I have also tried the oh.doIt(); function as suggested in some books, but java seems to dislike this and say it cannot find symbol doIt()
    Any help would be greatly appreciated!
    Excuse the formatting
    Thanks
    J Selby
    The package code:
    package useful;
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class oh {
    public void paint(Graphics g) {
    g.drawRect(100,50,200,50);
    The applet code:
    //Declare Java Libraries
    import useful.*;
    import java.lang.*;
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class calculator extends Applet
         Font screen = new Font("Tahoma", Font.BOLD, 11);
         public void init()
         // Set null layout - Gives freedom for button placement
         setSize(400,400);
         setBackground(new Color(36, 48, 74));
         setLayout(null);
    Button exit = new Button("Exit");
         Button go = new Button("Go");
         add(exit);
         exit.setLocation(155,10);
              exit.setSize(40,22);
    add(go);
         go.setLocation(120,10);
         go.setSize(25,22);
    Choice tech=new Choice();
    tech.addItem("Tutorial Menu");
    tech.addItem("Applet A");
    tech.addItem("Applet B");
    tech.addItem("Applet C");
    tech.addItem("Applet D");
    tech.addItem("Applet E");
    tech.addItem("Java Quiz");     
    add(tech);
         tech.setLocation(10,10);
         oh oh = new oh();

    From your code it is no where written that you are using the package called graphics
    You are been using
    package useful;
    this implies u r using the package called useful
    well let me tell you how to use packages.
    For example if you use a package called pack1
    then that file you need to compile from parent directory as
    javac -d filename.java
    this will give you the folder called pack1 and the compiled file placed in it..
    so to use this in other folder from parent directory then
    you have to import that file
    import pack1.filename;
    then this will allow you to acess all the methods from that class file..
    i hope you get me if any concerns can mail me at
    [email protected]

  • How do I unblock Java applet

    Installed new version of Java.  Now Safari Blocks Java applet for Yahoo Games  I've tried Sys preferences and Safari preferences  Would value suggestion on how to unblock

    In the address bar you should see a plugin icon that looks like a "lego". If you click on it you will see buttons to "Allow" or "Allow and Remember". See this article for a screenshot and more information:
    *[[How to allow Java on trusted sites]]
    Does that solve the problem?

Maybe you are looking for

  • ITunes radio and multiple Apple ID's

    I have a Match subscription under my Apple ID...my wife and kids share the same ID for the iTunes Store, but have individual Apple ID's for our iDevices. If they use iTunes radio, they see my stations. Can they sign into iRadio undet their own Apple

  • How to use Dashboard as a cut & paste software

    Hi ! I´ve hard to understand the function of "Dashboard" - I thought that the software could be a help for me to cut/copy pictures on websites for an example - I thought that I could mark an area on a site, copy the are and save it to iPhoto or copy

  • ATI Rage 128 Pro

    Can it run apple 23 lcd?

  • You cannot post write-ups

    Guru's we are getting this error message while posting the write up for a asset which has Accumulated depreciation for the pervious year as well as normal planned depreciation in the current year. You cannot post write-ups Message no. AA400 Diagnosis

  • Certification (1Z0-141)

    Hi, Does anyone know if there are any good study guide books for the 'Oracle Forms: Build Internet Applications' (1Z0-141) exam? I have had a look on the Oracle website and they just seem to recomend there rather expensive study CD!