Webserver use, configuration and management
In order to make full use of dynamic pages, there needs to be a way of getting information from the user's browser to the server. The most common mechanism is an HTML form. The example below shows one and the HTML used to generate it.
When the user clicks the Submit Query button, an HTTP request is sent to the URL identified in the Form tag's action. The request will use the HTTP method specified in the form tag, and will encode the contents of the form either in the URL (if the method is GET) or in the body of the request (if the method is POST).
<FORM METHOD=GET ACTION="/cgi-bin/mycgi.bat"> <p> Which lecture are you missing? (Give the lecture number not title) <INPUT NAME="WUCMI_unit" TYPE=int> <p> When will you come to collect them? <ol> <li>Next lecture <INPUT NAME="collect_type" TYPE=checkbox VALUE="NextLecture"> <li>Next tutorial <INPUT NAME="collect_type" TYPE=checkbox VALUE="NextTutorial"> <li>At 5:00pm on Friday this week <INPUT NAME="collect_type" TYPE=checkbox VALUE="Friday"> </ol> <p> Your CAM number? <INPUT NAME="cam_num" id="cam_num" SIZE=20> <hr> <p> <INPUT TYPE=submit> <INPUT TYPE=reset> </FORM>
The request is processed by the server. To generate dynamic content, the server needs to be set up to recognise the URL as requiring a program to be run, rather than simply delivering a file. Provided this is the case, the server will execute the program, passing the form data (and some other information) to it. Anything output by the program is collected by the server and parcelled up to form the response to the request. Thus, the output of the program is passed back to the user's browser. It is the responsibility of the program to ensure that what it outputs will make sense to the browser, so it is important to get both the headers and the contents of the response correct.
The HTTP protocol provides a set of methods that are used to signify the type of action the request asks the server to make (in relation to the specified URL). GET is the usual method for a browser to request retrieval of data from a server. This is the method used when you click on a link in an HTML page, for example, or if you type a URL into your browser's address bar. GET is one of two methods commonly used in HTML forms - the other being POST, which should be used whenever you are asking for information on the server to be modified (e.g. entering data into a database; adding an item to a shopping basket).
There are two ways by which the data from a form can be passed to the server in an HTTP request. If the method is GET, the data will be encoded as part of the URL For example:
GET /cgi-bin/mycgi.bat?WUCMI_unit=78&collect_type=NextTutorial&dis_num=67 HTTP/1.0 <headers...>
If the method is POST, the data will be encoded in the body of the request. For example:
POST /cgi-bin/mycgi.bat HTTP/1.0 <headers...> WUCMI_unit=78&collect_type=NextTutorial&dis_num=67
In both cases, "&" is used to separate out the parameters, and "=" is used to separate the name and value of each parameter. Special characters need to be encoded. A space in a name or value is replaced by "+". Other characters are encoded using the hexadecimal form of the character's ASCII code number - for example, %20 is another way of denoting a space. In the GET case, the parameters are separated from the URL by the "?" symbol.
There are four broad ways of generating dynamic content in response to an HTTP request.
We will briefly look at each, focusing on CGI. The server module approach (e.g. for PHP) is covered in the WEBSPR unit. The auxiliary server approach is covered in the MSc WEB1P and WEB2P units.
For more information on passing data to a server-side program see this section of my WEB1P notes. It includes an example of how to decode the data in a Perl script.
I have also have an extensive set of notes and links on Java web programming.