How to Communicating with cgi forms

So you've seen how Java applets can read data from cgi programs. getting information about forms based things needs a little more coding.

Protocols

There are two ways of sending data to forms

The protocol for talking to cgi-bin scripts is:

  1. create a URL.
  2. open a connection to the URL.
  3. get an output stream from the connection. This output stream is connected to the standard input stream of the cgi-bin script on the server.
  4. write to the output stream.
  5. close the output stream.
  6. get any data returned on the standard output stream of the cgi-bin script


Encoding

You might need to encode the data sent to the cgi-bin using the URLEncoder class. This is because most cgi-scripts expect to get data in a MIME format called x- www-form-urlencoded.


Example

In order to run this example, you need to install the following two programs into the cgi-bin directory of your httpd server. (sorry only for servers that have perl)

OK I've done it lets go on