Getting images in applet

K

Kevin C.

I have an applet that reads jpg's. It works in AppletViewer but I get a
permission block for reading the file when I load it in my browser (all the
files in this case are local). How would I get permissions for it it to run
in a browser, and what would I need to do if I were to upload this to a
website?
 
A

Andrew Thompson

I have an applet that reads jpg's. ...
Applet.getImage(URL)

...get permissions..

URL's can reach resources at your web site
without any code signing or extra permissions.

HTH
 
K

Kevin C.

In case it matters:

I am making a call to ImageIcon("example.jpg"). No URL/path. The class files
and the jpgs are in the same directory.
 
A

Andrew Thompson

I am making a call to ImageIcon("example.jpg").

If it is an applet, use getImage(),
so it is compatible with 1.1 VM's,
if you are using JApplet, ..use
getImage() anyway, it inherits it
from Applet.
..No URL/path.

You will need to use an URL
or sign your applet.

Any whiff of a 'File' in an unsigned
Applet (or JApplet) and the SecurityManager
will stomp on it.
 
D

Dave

Kevin C. said:
I have an applet that reads jpg's. It works in AppletViewer but I get a
permission block for reading the file when I load it in my browser (all the
files in this case are local). How would I get permissions for it it to run
in a browser, and what would I need to do if I were to upload this to a
website?

Hi Kevin,

Short answer: Change your browser Java security settings to allow
access...

You may want to catch security exceptions in your applet, and when you
catch one, inform the user that they must change their security settings.

The method/tools used to change these settings vary with each web
browser (and for Applications, with each system).

File access priveleges for Java applets are usually kept "wide open" for
Applet Runner applications which can only run 'local' files (yeah, I
know, they don't have to be very local).

But web browsers usually have their own settings for file access,
network access, etc, because they are usually running untrusted applets
from unknown remote servers. Browsers usually allow access to ALL Java
files, but restrict files of other types by default. In MacIE5, these
settings are in Edit: Preferences...: Web Browser: Java: Security
Options. In WinIE they are way out in the middle of nowhere - I think
it was in Advanced: Blah: Blah: Java or Advanced: Blah: Blah:
Security... It's been a while...

On the Macintosh OS8/9 platform, some security settingd for applications
are controlled by a tool called JBindry. This is done on an application
by application basis, and requires creating a 'preferences file' for
each application. In return, the Java application becomes a first class
double clickable application, complete with icon, memory settings and
system preferences like all other applications. JBindry controls byte
code verification (on/off), Java proxy settings, and Java Firewall
settings.

Applet Security restrictions are lifted for Trusted Applets (with Java
security certificates), when the user approves the applet. Getting a
certificate for your applet will virtually allow you to ask the user to
lift the restrictions by simply clicking a dialog button. Highly
recomended...

You might want to read: http://java.sun.com/sfaq/

Clearly, any method that can throw a SecurityException can potentially
fail to work properly if there is a security issue, so watch for that...

There is also a file called "java.security" somewhere on each system
which contains some security settings. The file is essentially human
readable, but not human editable (an error could prove fatal).

Hope this helps...

--Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top