Hi SO,
I am building a Java Applet that is running local that needs to access a couple of images on my webserver. How can i load images from a given webserver in java?
Hi SO,
I am building a Java Applet that is running local that needs to access a couple of images on my webserver. How can i load images from a given webserver in java?
Use Image i = getAppletContext().getImage(new URL("...."));
. Note that per the default Applet security policy, you will be able to access only URLs that reside on the same host as the applet.
If you wish to access images on another server, you need to edit the java.policy of the JRE that your browser java plug-in is using. For example, on a windows machine with Java 6, this will normally be:
%PROGRAM FILES%\Java\jre6\lib\security\java.policy
For example, to give socket permissions for connecting to an image server, to applets originating from localhost, you'd add something like this to the java policy file:
grant codeBase "http://localhost/-" {
permission java.net.SocketPermission "imgserver.company.com", "connect, resolve";
};
Where imgserver.company.com is the server your applet needs to connect to in order to fetch the images.
DISCLAIMER: Careful when editing the java policy for your browser, because potentially you could be giving more permissions to not just your own applet, but to other, malicious applets.