• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Once again - applets and files on the webserver

 
Erick Smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read through this board in hopes of finding an answer to my question, and although there's much discussion I'm still confused.
I have an applet that needs to load some gif images from the server. I have a webserver running, and the applet is loaded through the webserver, but it still throws a security exception when I try to load the image. Here's an example of the code:
JButton planButton = null;
planButton = new JButton(new ImageIcon("images/Planet.gif"));
planButton.setToolTipText("Switch to Planetary/Map Screen");
toolBar.add(planButton);
Now I'm confused as to whether I need to use URL.getConnection and such to access the image object, or if I have to make a server program that handles the request? Shouldn't the applet be able to load the image because the image is located on the same machine that the applet was downloaded from?
Sorry to ask a question that seems to be asked a lot, but I'm still confused.
Thanks,
Erick

[This message has been edited by Erick Smith (edited April 25, 2000).]
 
Erick Smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few more thoughts on what I should do...
Would a applet/servlet configuration work here?
Do I need to changer the file.io permission on my web server computer?
Any insight would be greatly appreciated,
Erick
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just looked at the docs for ImageIcon, and it has a handy URL constructor. Just changing your code above to:

(where someserver.com is the address of your server, of course) should do the trick.
 
Erick Smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much! This works beautifully. I had actually found this info in the tutorial, but had still screwed it up som (heh)
Anyway, for those who may still be experiancein this wonderful security feature, here's the actual code that I used that works:
try
{
url = new URL(getCodeBase(),"images/Planet.gif");
}
catch (MalformedURLException e)
{
System.err.println(e.toString());
System.exit(1);
}
catch (IOException e)
{
System.err.println(e.toString());
System.exit(1);
}
JButton planButton = null;
planButton = new JButton(new ImageIcon(url));
planButton.setToolTipText("Switch to Planetary/Map Screen");
toolBar.add(planButton);
That should be clear enough to help out when this problem arises again!
Thanks again,
erick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic