17.1. Sending Data with GET and Displaying the Resultant Page

The showDocument method instructs the browser to display a particular URL. Recall that you can transmit GET data to a servlet or CGI program by appending it to the program's URL after a question mark (?). Thus, to send GET data from an applet, you simply need to append the data to the string from which the URL is built, then create the URL object and call showDocument in the normal manner. A basic template for doing this in applets follows, assuming that baseURL is a string representing the URL of the server-side program and that someData is the information to be sent with the request.

 try { URL programURL = new URL(baseURL + "?" + someData); getAppletContext().showDocument(programURL); ...

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.