/* * This applet is used to notify me when a user moves away from the page. * It works by opening a connection to a cgi-script on the machine where * the page was picked up from when the stop() method is called. * Note: this works under current Netscape security restrictions, as it * only connects home and doesn't try to actually open any streams (all * info is passed via the query string). */ import java.applet.Applet; import java.net.*; public class NotifyPageExit extends Applet { private final String cgi = "/cgi-bin/return_files"; private String query; public void init() {} public void start() { query = getParameter("query"); } public void stop() { URL home; try home = new URL(getDocumentBase().getProtocol(), getDocumentBase().getHost(), getDocumentBase().getPort(), cgi+"?"+query); catch (MalformedURLException e) return; try home.openConnection().connect(); catch (java.io.IOException e) return; } } The HTML to use the above applet: " GetURL.java: /* * Run this with: java GetURL dir URL [ URL ... ] * This program takes a list of URLs and copies the contents to files * with the same name as in the URL (minus the path); these files are * put in the directory 'dir'. */ import java.net.*; import java.io.*; class GetURL { static final int buf_size = 4000; // size of buffer used for copying public static void main (String args[]) { int idx, tail, numb, dir_idx = 0; boolean noisy = false; byte buffer[] = new byte[buf_size]; String outfile; URL url; InputStream in; FileOutputStream out; /*** get command line options ***/ while (dir_idx < args.length && args[dir_idx].startsWith("-")) { if (args[0].equals("-noisy")) { noisy = true; } else { System.err.println("Unknown option: "+args[0]); return; } dir_idx++; } /*** check for correct number of command line arguments ***/ if (args.length < dir_idx+2) { System.err.println("Usage: java GetURL [-noisy] directory URL "+ "[URL ...]"); System.err.println(" copies the files specified by the "+ "URL's into directory"); return; } /*** Get the files ***/ for (idx=dir_idx+1; idx