We know that the Javaapplet in the Web page is not like the image file can be directly from the browser to the SaveAs command to obtain, but still may be browsed from the cache to find, put their own web page. Therefore, one way to protect your applet from "stealing" is to have the applet run only on the Web page of the specified URL. In the Java language, the URL of the Web page where the applet resides can be obtained by means of a method getdocumenbase () in the Java.applet package.
For example, in the following procedure, the applet detects the current URL in the initialization phase and, once it does not match the setting, outputs the warning message in the Java Console (Javaconsole) and automatically aborts the operation, thus enabling the applet's "copyright protection".
import java.net.*;
import java.applet.*;
public class myonly extends Applet{
public void init(){
String ower=getDocumentBase().getHost();
if(!ower.equals("www.mydomain.com")){
System.out.println("Warning ! A stolen Applet.");
System.exit(1);
}
else{
… …
}
}