|Computer Science Fundamentals
The lab discusses some basic elements of CGI programming, which allows a Web developer to tailor documents to an individual Web user.
Run the http://www.walker.cs.grinnell.edu/cgi-bin/what-i-know-script.cgi script, to see what is printed.
Copy the what-i-know-script.cgi script and the Scheme program what-i-know-script.ss to your account, and share each program. Then try running your copy of the script from your Web browser.
Add comments to the Scheme program what-i-know-script.ss to annotate what each section of code is doing.
Add a couple lines at the end of the program, so that the program displays your name at the bottom of the Web page it produces.
Query strings represent a mechanism for a browser to pass information along to the Web server for use in a CGI script and program. Frequently, Web pages include an html device, called a form for this purpose, but the same information may be included directly in a URL by typing a question mark ? and then adding the relevant data.
The following exercises utilize a directory of the 1998-1999 faculty in the Mathematics and Computer Science Department at Grinnell College.
Fill in the requested information in http://www.walker.cs.grinnell.edu/cgi-bin/fac-directory.html, to determine information about Henry Walker and about John Stone. (Also, look under Nathaniel Borenstein and Pamela Ferguson -- who shared an office during the 1998-1999 academic year.)
To view this form itself, click on the above document and then ask your browser to view the page source. There, you will see that the submit input will result in the action of requesting the CGI script fac-directory.cgi. Similarly, you will find the labels and field names for each input textual field.
When Henry is entered into the First Name box and Walker is entered into the Last Name box, then when the user clicks the submit button, a request is generated to the Web server -- as shown in step B above.
Instead of using this html form, type the line http://www.walker.cs.grinnell.edu/cgi-bin/fac-directory.cgi?firstname=Henry&lastname=Walker as the URL directly into your browser. Note that the result is exactly the same as using the form. That is, the html form within fac-directory.html simply provides a convenient way to generate URL addresses with query string information added.
Modify the what-i-know-script.ss program, which you annotated and expanded earlier in this lab, to display any query string which is included in a URL to the script what-i-know-script.cgi. Thus, if you typed the URL
http://www.cs.grinnell.edu/~yourUsername/cgi-bin/what-i-know-script.cgi?IlikePOPCORN!the program should include the following text in its output
In CGI programming, a query string usually consists of a sequence of equations separated by ampersands, with some attribute on the left-hand side of each equation and the value of that attribute on the right-hand side. For instance, in our form example, the query string had the form firstname=Henry&lastname=Walker. As noted in the reading for this lab, it is common to decode query strings to yield an association list of field names and associated values. The library routine extract-attributes procedure in http://www.walker.cs.grinnell.edu/public_html/cgi-bin/cgi-utilities.scm accomplishes this task. This Scheme code, written by John Stone, takes a query string as argument and returns a list of pairs, with the car in each pair being a fully decoded attribute and the corresponding cdr being its fully decoded value:
For steps 3, 4, 8, 11, and 12, only a printout of the relevant files are needed. You need not show a run of the program (as any run will show up in your Web browser rather than in a window that you can record).
This document is available on the World Wide Web as
created November 3, 1998
last revised March 7, 2005
|For more information, please contact Henry M. Walker at firstname.lastname@example.org.