SecurityException in Java Applet
Hi,
I made a Applet but when I put an <APPLET> tag in my HTML, occurs an exception
SecurityException : Could not open file policy C:\Program Files\Java\jdk1.7.0_05\bin\raystore: sun.security.provider.PolicyParser$ParsingExceptio n line 1: expected [;] found[pípí]
I tryied to follow this sample, but I don't know what to do in step 7.
Can anyone help me ?
Re: SecurityException in Java Applet
You're using very old sample. This book is from 1999, and some examples from this sample are from 1998.
You should use newer samples and examples for learning. Lots of things have changed since 1999.
Instead of using "import java.applet.Applet;" now in usage is "import javax.swing.JApplet;"
Newer version for old sample code for class SignedAppletDemo.java (from your sample) would be something like that:
Code:
import java.awt.Color;
import java.awt.Graphics;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JApplet;
public class SignedAppletDemo extends JApplet {
public String test() {
setBackground(Color.white);
String fileName = System.getProperty("user.home") +
System.getProperty("file.separator") +
"demo.ini";
String msg = "This message was written by a signed applet!\n";
String s;
try {
FileWriter fos = new FileWriter(fileName);
fos.write(msg, 0, msg.length());
fos.close();
s = new String("Successfully created file :" + fileName);
} catch(IOException e) {
System.out.println("Exception e = " + e);
e.printStackTrace();
s = new String("Unable to create file: " + fileName);
}
return s;
}
public void paint(Graphics g) {
g.setColor(Color.blue);
g.drawString("Signed Applet Demo", 120, 50);
g.setColor(Color.magenta);
g.drawString(test(), 50, 100);
}
}
Re: SecurityException in Java Applet
Thanks. But when I put the Applet in my Web Application, occurs the ExceptionInInitializerError. My applet extends from JApplet.
Re: SecurityException in Java Applet
^Please give us full error message.
Re: SecurityException in Java Applet
How can I do that? The warning message just show me the name of the exception, nothing more. Without html, works fine.
Re: SecurityException in Java Applet
^This is one example of ExceptionInInitializerError message. This error message has maybe 30-40 lines:
java.lang.ExceptionInInitializerError
at org.openscience.cdk.libio.cml.Convertor.cdkAtomCon tainerToCMLMolecule ( Convertor.java:184 )
at org.openscience.cdk.libio.cml.Convertor.cdkMolecul eToCMLMolecule ( Convertor.java :180 )
at org.openscience.cdk.io.CMLWriter.write ( CMLWriter.java:173 ) ... 10 more
and
Caused by: java.security.AccessControlException: access denied ( java.util.logging.LoggingPermission control )
at java.security.AccessControlContext.checkPermission ( Unknown Source )
at java.security.AccessController.checkPermission ( Unknown Source )
at java.lang.SecurityManager.checkPermission ( Unknown Source )
at java.util.logging.LogManager.checkAccess ( Unknown Source )
at java.util.logging.Logger.setLevel ( Unknown Source )
at org.xmlcml.cml.element.CMLMolecule. < clinit > ( Unknown Source )
... 19 more