Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Security Exception for showing images

 
Sam Tilley
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i am trying to make an applet to show simple images. The code compiles fine but the applet won't load up in my browser (IE5.5) and displays the following in my Java console.

The exception is shown below


I have read up a bit about Security Exceptions but cannot seem to find what i need to get this program to work.
I will be working with applets to retrieve data and images from a database / server files quite a bit and need to look up this topic quite well so is there also anything out there (good sites) that will help me out apart from the Sun documents.
Thanks
[ May 10, 2002: Message edited by: Sam Tilley ]
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default behavior of the JVM "sandbox" is to prohibit the applet from being able to load files from the local file system. This is to prevent malicious code from examining the contents of a user's hard drive, and perhaps sending files to some server (stealing them, etc.)
You can load images from the web server to which you are connected. If you really need to load local files, you'll have to change the security policy for the applet to allow this.
 
Sam Tilley
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers Rob, so i need to post my applet and gifs up to my website for example and operate it from there???
My problem remains that to develop code to make it work i have to post it to my server each time and this could be quite a long winded way of doing it... But then i suppose if it keeps it safe it should work ok
Bit of trial and error needed i feel
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For strictly testing purposes you can either run your applet in AppletViwer, which has all security permissions turned on by default, or create a testing security profile which allows your applet to load files from the file system. This can simplify your edit-compile-run cycle, but you have to understand it won't work when you deploy your applet to the "world."
You can try to reference all your gifs as relative to your document base (getDocumentBase()), because this uses a URL and only loads the files from your web server, which is allowed.
You can also get your images as a resource (see Classloader.getResource()), and if you have packaged all your needed gifs in the same classpath along with your .class files, those gifs are then available to your applet since they're downloaded along with your .class files (embedded in the jar file).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget, you could just install a very simple and free server on your development machine for testing purposes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic