Javascript returns the error message "Typeerror: applet.returnMD5 is not a Function" when calling Applet method

Asked

Viewed 576 times

1

My applet is signed and all his methods are public.

This error message appears for all browsers I have tested.

Follows the codes:

Main java.

public class Main extends Applet {

private String ip;
private String macLocal;
private String md5;
private InetAddress ipLocal;

@Override
public void init() {
    super.init(); //To change body of generated methods, choose Tools | Templates.
}



public String returnIp(){
    try {
        ipLocal = InetAddress.getLocalHost();
        ip = ipLocal.getHostAddress();
    } catch (UnknownHostException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    return ip;
}
public String returnMac(){
    try {
        ipLocal = InetAddress.getLocalHost();
        NetworkInterface network = NetworkInterface.getByInetAddress(ipLocal);
        byte[] mac = network.getHardwareAddress();
        StringBuilder sb = new StringBuilder();
    for (int i = 0; i < mac.length; i++) {
        sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));        
    }
            macLocal = sb.toString();
    } catch (SocketException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnknownHostException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    return macLocal;
}
public String returnMD5(){
    try {
        MessageDigest m=MessageDigest.getInstance("MD5");
        String ipMaisMac = new StringBuffer(retornaIp()).reverse().toString() + new StringBuffer(retornaMac()).reverse().toString() ;
        m.update(ipMaisMac.getBytes(),0,ipMaisMac.length());
        BigInteger i = new BigInteger(1, m.digest()); 
        md5 = String.format("%1$032X", i); 
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    return md5;
}

js encryption.

function encript() {
    var applet = document.getElementById("principal-object")
    alert(typeof(applet));
    if(typeof(applet) == "undefined") {
        alert("Undefined")
    } else {
        document.getElementById("token").value = applet.returnMD5();
        document.getElementById("local_ip").value = applet.returnIp();
        document.getElementById("tolocal_macken").value = applet.returnMac();
    }
}

index.html

<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src="encript.js"></script>
</head>

<body onload="encript()">
    <form action="login.php">
        Login:
        <input type="text" name="login" value="" /> Password:
        <input type="password" name="password" value="" />
        <input type="hidden" name="local_ip" id="local_ip" value="00" />
        <input type="hidden" name="local_mac" id="local_mac" value="00" />
        <input type="hidden" name="token" id="token" value="00" />
        <button>Login!</button>
    </form>
    <object id="principal-object" width="256" height="256">
        <param name="archive" value="Encript.jar" />
        <param name="code" value="br.com.encript.applets.Main" />
        <param name="mayscript" value="true" />
    </object>
</body>

</html>
  • I don’t understand much, but it seems a cast error. Don’t have to convert first to type Main and then call the function?

1 answer

0

Applets have become obsolete, most modern browsers no longer support any of the technologies that used Applets (Java, Flash, etc.). And its use in the creation of websites is highly not recommended, because there are no plans (and probably never will be) to make an "official" specification for these technologies.

  • I understand. But I can even use applets when I’m only using the applet without interacting with any html or javascript components. That’s the problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.