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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.