Domanda

I have to delete some temporary file from a users system when he logs out of application. The application has applet. The applet jar is signed. I am following the strategy to call the applet's destroy method to delete files. I am invoking the destroy method of applet by javascript like document.myApplet.destroy() . After invoking this I am getting the error on browser as

Uncaught Error: java.security.AccessControlException: access denied (java.io.FilePermission Uncaught Error: Error calling method on NPObject.

È stato utile?

Soluzione

Ok I got the answer myself: After refering to this link http://docs.oracle.com/javase/7/docs/api/java/security/AccessController.html , I figured out ,that reading,writing or even deleting can be done by wraping them up in AccessController.doPrivileged method.

AccessController.doPrivileged(new PrivilegedAction() {

                @Override
                public Object run() {
                    try {
                        deleteAppCacheDirectory();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

            });

Altri suggerimenti

You should remove the call to the destroy method from your javascript code. The destroy method is automatically called by the browser when the user leaves the page. The reason this is happening is probably because your destroy method is not public. This doesn't prevent the browser from calling it, however.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top