How Do I Ensure Secure Communications from a Java Applet?

By Kenneth Golomb and Thomas Sorgie

Dr. Dobb's Journal June 1998

//URL encode the data to the x-www-form-urlencoded MIME format
String urlEncodedData = URLEncoder.encode(data);
System.out.println("URL Encoded Data: " + urlEncodedData);
//Instance the URL (protocol, host, port)
String protocol = getCodeBase().getProtocol();
int  port = getCodeBase().getPort();
String host = getCodeBase().getHost();
URL url = new URL(protocol, host, port, "/servlet/ProxyServlet");
System.out.println("Destination URL: " + url.toString());
//Open the connection
urlConnection = url.openConnection();
//Turn off the caching feature
urlConnection.setUseCaches(false);
//Set the URL to POST instead of GET
urlConnection.setDoOutput(true);

Example 1: HTTP URLs function like regular sockets.

Back to Article


Copyright © 1998, Dr. Dobb's Journal