Reputation: 3520
I have a java applet which is hosted on a device's web page. The applet needs to retrieve data from the device at runtime. Currently the device is configured to output the required data out port 8080 (so, say, 192.168.1.1:8080). How would I inform my applet of its host web page's URL so that it would know where to get the data from?
Thanks, John
Upvotes: 2
Views: 1357
Reputation: 35417
Use Applet#getCodeBase(). This method returns the URL of the directory which contains this applet.
import java.applet.*;
import java.awt.*;
public class FromWhere extends Applet {
public void init() {
Label label = new Label(getCodeBase().toString());
add(label);
}
}
Note : NULL is returned if the applet is loaded from the file system since JDK1.7b25
Upvotes: 1