A form in HTML is an area of a Web page which is used to gather input from a human user. The information which is gathered can then be returned to the page's owner using a SUBMIT action.
The form is, as expected, delimited by a <FORM> and </FORM> markup pair.
The <FORM> markup has two important attributes:
<FORM ACTION="http://ironbark.bendigo.latrobe.edu.au/cgi-bin/myprog METHOD="GET">
For example:
This INPUT type can take several further attributes, eg:<INPUT TYPE="TEXT"
In a browser, this would be presented as a (scrollable) textbox, 20 characters wide (but able to accept 64 characters of input).<INPUT TYPE="TEXT" NAME="Name" MAXLENGTH="64" SIZE="20">
There are several other INPUT types:
When form information is returned to the HTTP server, it is encoded into a format called:
In this format, space characters are replaced by "+", and non-printing characters are given in hexadecimal format, thus: %HH, where the H characters are the hexadecimal digits of the byte. The fields of a form are encoded as name=value, with each pair separated by the "&" character. Fields with null values are (normally) not sent, nor are unselected CHECKBOXes and RADIO buttons.application/x-www-form-urlencoded
In "real life", GET and POST methods are used pretty much interchangeably, depending on the programmer's preference.
When a user clicks the SUBMIT button on a form, the HTTP server starts up the specified CGI program, and makes the form data available to it.
The subtle difference between GET and POST is the way in which a CGI program receives the form data. If the method was GET, the information is usually obtained by examining the contents of environment variables containing the form values as well as some extra useful stuff.
If the method was POST, the CGI program usually receives the form data on its standard input stream, with the extra stuff obtained, as before, from environment variables.
CGI programs can, as a rule, be written in any language (compiled or interpreted) supported on the system running the HTTP server.
On Unix servers, they are commonly written in Perl, C or as Bourne shell (/bin/sh) scripts.
A CGI program (almost) always generates (to standard output) a Web page which is returned to the browser.
The <FORM> markup of this segment of HTML looks like:<html>
<head>
<TITLE>Test form for BITCNE Lecture #22 Example</TITLE>
</head>
<body bgcolor="#FFFFFF">
<h2>Test form for BITCNE Lecture #22 Example</h2>
<FORM action="/subjects/bitcne/cgi/L22CGI.cgi" method="GET">
Family Name: <INPUT type="text" name="family" size="20"><br>
Given Name: <INPUT type="text" name="given" size="20"><br>
<input type="submit" value="Get Information">
<input type="reset" value="Clear Form">
</FORM>
</BODY>
</HTML>
Note that you can press the "submit" button if you like...
This <FORM> is processed by the following CGI program (in Perl):
#!/usr/local/bin/perl -w
require "common.pl";
$webmaster = "P\.Scott\@latrobe\.edu\.au";
&parse_form_data (*simple_form);
print "Content-type: text/html", "\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE>This is what you sent me</TITLE></HEAD>";
print "<body bgcolor=#ffffff>";
print "<h2>This is what you sent me</h2>";
$family = $simple_form{'family'};
$given = $simple_form{'given'};
print "Given name: <strong>", $given, "</strong>.<br>", "\n";
print "Family name: <strong>", $family, "</strong>.<p>", "\n";
print '<a href="/subjects/bitcne/lectures/Lect22.html#form">Back</a>',"\n"; print "to the lecture notes.\n";print "</BODY>";
print "</HTML>";
exit(0);
Applets can make Web pages dynamic. Forms and CGI programs allow some two-way interaction, but with applets this interaction can occur in real time. In principle, there is no restriction on what an applet can do - everything from simple animations to full featured spreadsheets and word processors - all within the browser.
An applet is specified in a Web page as (eg):
<APPLET CODE="spread.class" WIDTH=200 HEIGHT=100> </APPLET>This reserves a rectangular space in the browser for the applet to execute in, then loads the applet from the server and runs it.
It is extremely important that applets execute in a secure way - ensured by the browser vendor.
Java is an object-oriented language with characteristics derived from C, C++, Pascal and Smalltalk. It has some weak aspects, but is generally regarded as a very good general purpose programming language.
Source code written in Java is compiled to a special form of binary executable file called bytecode. No (common) computer executes bytecode directly - it is the binary format for an abstract computer architecture, and is "executed" by a software bytecode interpreter.
A Java bytecode interpreter is built-in to most modern browsers. In addition, some browsers implement a Just In Time compiler, which converts the bytecode binary format into the format of the native processor on the fly, for much faster execution than interpretation, which is intrinsically slow.
Java programs are usually developed in a development kit, containing a bytecode compiler, standard libraries and a standalone bytecode interpreter (applet executor).
Finally, there is no reason why applets cannot be developed in other source languages once suitable bytecode compilers become available.