Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to load image from a subdirectory on server

 
the mask
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi frnds,
please help me with this. I am trying to display an image on the applet. the image resides in the "images/listBackgr.gif" directory on the server and the applet is placed on the root path. with i try to access the image from the Applet using the code following i get an error.
JLabel imgTry = new JLabel();
imgTry.setIcon(new ImageIcon(getCodeBase() + "/images/listBackgr.gif"));

The Error is......

java.security.AccessControlException: access denied (java.io.FilePermission http://localhost/envoy_ws_new/Live/EN//images/listBackgr.gif read)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
at java.security.AccessController.checkPermission(AccessController.java:
401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:486)
at sun.awt.SunToolkit.getImage(SunToolkit.java:500)
at javax.swing.ImageIcon.<init>(ImageIcon.java:81)
at javax.swing.ImageIcon.<init>(ImageIcon.java:107)
at ClassMatrix1.init(ClassMatrix1.java:143)
at sun.applet.AppletPanel.run(AppletPanel.java:348)
at java.lang.Thread.run(Thread.java:536)

could someone help me sort this problem out.....will i have to sign the applet???... or can i just solve it by making changes in the code.
Quick response is appriciated.
Thanx in advance.
Masky.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "The Mask"!
You can JAR your images directory with the Applet jar and then use getResource() which is there in the java.lang.Class. You will have to use this.getClass().getResource("/images/1.gif") I guess which will give you the URL that you can pass to ImageIcon constructor..
Regards
Maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic