Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie problem - My applet fails in browser

2 views
Skip to first unread message

Rob Jaeger

unread,
Sep 8, 2003, 10:48:45 AM9/8/03
to
I'm an experienced programmer working on my first Java applet in Eclipse.
All is well if I don't try to access any external files, but if I try to
even read a .jpg file, my applet fails (in browser). When testing within
the Eclipse environment, all is fine. My browser has the most current
version of Java.(2.1.4).

To no avail, I've tried:
making a JAR file, and including it in the html
editting java.policy.applet with explicit FilePermissions

TIA,

Rob

Larry

unread,
Sep 8, 2003, 12:30:06 PM9/8/03
to
Can you post the code that is trying to access the files?
And post and exception that is being generated?

Generally speaking, within an applet, you can only access files using URLs,
to access the directly as files, you will need to sign your applet and have
the user grant you the appropriate permissions.

"Rob Jaeger" <yogi...@yahoo.com> wrote in message
news:Xns93F06D8B4A447...@24.168.128.90...

Rob Jaeger

unread,
Sep 8, 2003, 12:58:10 PM9/8/03
to
"Larry" <l...@wow.com> wrote in
news:2K-dnRGjK4I...@wideopenwest.com:

> Can you post the code that is trying to access the files?
> And post and exception that is being generated?
>
> Generally speaking, within an applet, you can only access files using
> URLs, to access the directly as files, you will need to sign your
> applet and have the user grant you the appropriate permissions.
>

OK- I don't want to have a signed applet. I just need to read graphics
files. I was hoping that just using the filename was good enough.

The offending code:

// board
static Image imageBoard =
Toolkit.getDefaultToolkit().getImage("board.jpg"); /* fails in
browser, OK in Eclipse */

It doesn't work at all if I specify the full URL (syntax error???):

static Image imageBoard =
Toolkit.getDefaultToolkit().getImage
("http://www.normaldistribution.com/PokerCalc/board.jpg");


error (from Java Console):

java.security.AccessControlException: access denied (java.io.FilePermission
board.jpg read)


Full Java Console output:

java.lang.ExceptionInInitializerError

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.security.AccessControlException: access denied
(java.io.FilePermission board.jpg 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 sun.awt.SunToolkit.getImageFromHash(Unknown Source)

at sun.awt.SunToolkit.getImage(Unknown Source)

at aFont.<clinit>(aFont.java:49)

... 11 more

java.lang.NoClassDefFoundError

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Roedy Green

unread,
Sep 8, 2003, 2:00:31 PM9/8/03
to
On Mon, 08 Sep 2003 16:58:10 GMT, Rob Jaeger <yogi...@yahoo.com>
wrote or quoted :

>OK- I don't want to have a signed applet. I just need to read graphics
>files. I was hoping that just using the filename was good enough.

However, if the system let you read that file, you could go looking at
the user's porn collection just as easily. That would be quite and
embarrassing thing for an enemy to be able to do.

That is why there are signed Applets and why your Applet can't go read
an arbitrary file without permission.

It is not that hard. See
http://mindprod.com/jgloss/signedapplets.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

AJ

unread,
Sep 8, 2003, 2:27:42 PM9/8/03
to
Rob Jaeger <yogi...@yahoo.com> wrote in message news:<Xns93F06D8B4A447...@24.168.128.90>...


Can we see some code? More specifically, any code involving the
instantiation of the Image object, and all references to it? Also,
what environment are you working in? *nix? What are your permissions
for the JPEG? should be readable by everyone.

Rob Jaeger

unread,
Sep 8, 2003, 4:45:56 PM9/8/03
to
Roedy Green <ro...@mindprod.com> wrote in
news:jqgplvsa7v09b5af2...@4ax.com:

> On Mon, 08 Sep 2003 16:58:10 GMT, Rob Jaeger <yogi...@yahoo.com>
> wrote or quoted :
>
>>OK- I don't want to have a signed applet. I just need to read graphics
>>files. I was hoping that just using the filename was good enough.
>
> However, if the system let you read that file, you could go looking at
> the user's porn collection just as easily. That would be quite and
> embarrassing thing for an enemy to be able to do.

Thanks, Roedy. I understand the security situation. For this applet, I
just need to load some graphics files that reside on the server with the
.html and the .class. The graphics load fine from html, and the file
permissions are fine.

When I use the full URL like this:

static Image imageBoard =
Toolkit.getDefaultToolkit().getImage
("http://www.normaldistribution.com/PokerCalc/board.jpg");

it fails even in the Eclipse environment. Is there something wrong with
my syntax? You can see that the URL works.

Thanks for your help & patience,

Rob

Roedy Green

unread,
Sep 8, 2003, 5:03:24 PM9/8/03
to
On Mon, 08 Sep 2003 20:45:56 GMT, Rob Jaeger <yogi...@yahoo.com>
wrote or quoted :

>Thanks, Roedy. I understand the security situation. For this applet, I

>just need to load some graphics files that reside on the server with the
>.html and the .class. The graphics load fine from html, and the file
>permissions are fine.

the easiest way to do that is to put them in the jar and get them with
getResource.

The usual way you trip over security is trying to pick them up from a
different server from the one that loaded the Applet.

Larry

unread,
Sep 9, 2003, 7:00:26 AM9/9/03
to

"Rob Jaeger" <yogi...@yahoo.com> wrote in message
news:Xns93F0846F58358...@24.168.128.74...

> "Larry" <l...@wow.com> wrote in
> news:2K-dnRGjK4I...@wideopenwest.com:
>
> > Can you post the code that is trying to access the files?
> > And post and exception that is being generated?
> >
> > Generally speaking, within an applet, you can only access files using
> > URLs, to access the directly as files, you will need to sign your
> > applet and have the user grant you the appropriate permissions.
> >
>
> OK- I don't want to have a signed applet. I just need to read graphics
> files. I was hoping that just using the filename was good enough.
>
> The offending code:
>
> // board
> static Image imageBoard =
> Toolkit.getDefaultToolkit().getImage("board.jpg"); /* fails in
> browser, OK in Eclipse */

Here is your problem. You need to use the URL class to specify the URL,
passing the file name into the URL constructor, and passing the URL object
into getImage().


0 new messages