0

everyone!

I have a signed applet (named result in html) with a simple function as below:

    public  void killApplet() 
    {   
        AccessController.doPrivileged(new PrivilegedAction<Object>(){
           //@Override
           public Object run() {
           // kill the JVM
           System.exit(0); // or any other line here
           String str = "any string";
           return null;
        }
    }); 
    }

The Java script code is like:

    function exec_java() {
        document.result.killApplet();
    }

When I click the button to execute the java function:

<button type="button" id="buttontest" onclick="exec_java()">test</button>

It shows up an exception as below:

java.security.AccessControlException: access denied

(java.io.FilePermission C:\Program Files\Java\jdk1.6.0_18\bin read)

I am using Windows XP with IE version as below:

IE 7

Vision: 7.0.5730.13

Any expert and give me a clue how to make this exception gone? Additionally, the weird thing here is I can call a simple function without problem like below:

       public int getNumberOfLines(){
            return number_of_lines;
       }

Any help would be appreciated! PS: Can't post any images cos apparently I am 'new'! Does anyone have a working sample using?

    AccessController.doPrivileged(new PrivilegedAction<Object>()

Thanks!

Wu Bi

wubi
  • 1
  • 1

1 Answers1

0
// kill the JVM
System.exit(0);

An applet is a guest in a web page that might host other applets. Calling System.exit(n) is like the guest burning down the guest-house. Don't do that! As such, even a trusted applet is not allowed to invoke the method.

A better way to end an applet is to call:

showDocument(thanksForUsingOurAppletURL);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Really thanks for answering my question so soon! my point is not "System.exit(0);" this line. Instead I change it to any other function, like "string a = 'any thing';", I still have another exception as "object doesn't support this property or method." I have been trying to read almost everything on web. Anybody can really help me out here? – wubi Mar 04 '12 at 16:13