A.17. Using Applets As Servlet Front Ends

Sending Data with GET and Displaying the Resultant Page

String someData =
  name1 + "=" + URLEncoder.encode(val1) + "&" +
  name2 + "=" + URLEncoder.encode(val2) + "&" +
  ...
  nameN + "=" + URLEncoder.encode(valN);
try {
  URL programURL = new URL(baseURL + "?" + someData);
  getAppletContext().showDocument(programURL);
} catch(MalformedURLException mue) { ... }

Sending Data with GET and Processing the Results Directly (HTTP Tunneling)

  1. Create a URL object referring to applet's home host. You usually build a URL based upon the hostname from which the applet was loaded.

     URL currentPage = getCodeBase(); String protocol = currentPage.getProtocol(); String host = currentPage.getHost(); int port = currentPage.getPort(); ...

Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.