Goals: This laboratory exercise introduces a general framework for documents which you routinely find on the World-Wide Web. The lab also begins a discussion of CGI programming, which allows a Web developer to tailor documents to an individual Web user.
To get started understanding how this document is produced in the given format, follow these steps:
In the new source window, note that all formatting commands are listed in angle brackets: < > . Many commands apply for a section. For example, <b> indicates the beginning of a section which should be printed in a bold type face, and </b> indicates the end of the same section. As in this example, in many cases, the formatting commands at the start and at the end of a section have the same name, but an extra slash / is added to the end marker.
The following table gives some main formatting commands illustrated in this example:
|<html >||begin an HTML document|
|<head>||begin the header section|
|<title>||begin a title|
|<body>||begin the body of the document|
|<h3>||begin a header3 section (headers can be h1, h2, h3, h4)|
|<p>||begin a new paragraph|
|<br>||break a line (begin a new line)|
|<b>||begin bold type face|
|<i>||begin italics type face|
|<hr>||draw a horizontal line|
|<blockquote>||display the section exactly as formatted|
[For more information about HTML, you might try the primer A beginner's guide to HTML, currently maintained by Marty Blase of the National Center for Supercomputing Applications.]
Follow these steps to copy this sample lab to your account in a way that will be accessible to the World-Wide Web:
Before anything in your MathLAN account can be accessed on the Web, you must make your home directory accessible. To do this, open a dtterm window and give the command
chmod 755 ~
at the prompt. (The symbol ~ stands for your home directory.)
Any materials related to the World Wide Web belong in a subdirectory of your home directory named public_html. If you have no such subdirectory, create one by giving the command
in the dtterm window. This directory, too, must be accessible; give the command
chmod 755 ~/public_html
to make it so.
Copy the sample program to your public_html directory in two steps: First move from your home directory to the public_html directory with the command:
cd public_htmlThen copy the file to your current directory (which is public_html) with the command:
cp ~walker/public_html/courses/151.fa98/lab-sample.html sample.htmlThe copy of the file will have the name sample.html .
Share your copy of sample.html with the command:
chmod 755 sample.html
Load this file into your Web browser by entering the URL:
http://www.cs.grinnell.edu/~yourusername/sample.htmlNote that when you specify a URL, the Web server automatically looks in your public_html directory, so you do not need to include that directory name in what you type.
Edit this file with XEmacs, trying some variations of the wording and trying some of the formatting tags described above. At the very least, change the address at the bottom of the Web page to your username and file name. Also, update the date created and last revised.
After each modification, use the reload button on your browser to check your revised version of sample.html .
Edit the file further, leaving out the initial < html > tag. Reload and describe what happens. Then reinsert this tag, and try omitting some other closing elements, reload, and describe what happens.
Change the <h3> to <h2> or <h1> or <h4>, and describe what happens in each case. Do you see any progression in style or format from <h1> to <h2> to <h3> to <h4> ?
In contrast, a dynamic document is produced by a program that can receive input from a user and modify the Web page based on that input. A typical mechanism for communication between a user's browser and a Web server is called the Common Gateway Interface (CGI). Altogether, the Common Gateway Interface (CGI) is a set of conventions, supported by software, that facilitate the writing of programs that generate World Wide Web documents. CGI programs can be written in almost any programming language; naturally, though, we'll use Scheme.
With CGI programming, the sequence of events for Web interaction has an extra step:
To expand on this idea, consider the following Scheme program:
(define writeln ;; This procedure writes multiple items one a line, (lambda args ;; and then goes to a new line. (for-each display args) ;; See Springer/Friedman, page 199, for details. (newline) )) (writeln "Content-type: text/html") (newline) (writeln "<html>") (writeln "<head>") (newline) (writeln "<title>") (writeln "title") (writeln "</title>") (writeln "</head>") (writeln "<body>") (writeln "<h2>" "Welcome to the world of Internet programming!" "</h2>") (writeln "<p>") (writeln "<i>" "This page is created by a Scheme program." "</i>") (writeln "</body>") (writeln "</html>") (newline)When this program runs, it prints the following
Content-type: text/html <html> <head> <title> title </title> </head> <body> <h2>Welcome to the world of Internet programming!</h2> <p> <i>This page is created by a Scheme program.</i> </body> </html>In order to have this program run in response to a Web request to a server, our instructions to the Web server must specify running Scheme and then executing the program. This is accomplished in two main steps:
(exit)This tells Scheme to quit when after running the program.
#!/usr/bin/csh /usr/local/bin/scm -q << ! (load "sample-script.ss") !While this file may look a little imposing, the pieces are not as bad as they may seem:
Altogether the above directions (with #!/usr/bin/csh ) is called a cgi script which, in turn, runs a Scheme program ( sample-script.ss ).
Putting these pieces together, we run our Scheme program by typing the URL http://www.math.grin.edu/~walker/cgi-bin/sample-script.cgi into our browser.
By clicking on this link, we call the instructions (with the C-shell), which in turn runs our program.
If you are not in the right directory, type
cd ~/public_htmlto move there.
mkdir cgi-bin chmod 755 cgi-bin
cp ~walker/public_html/cgi-bin/sample-script.cgi . cp ~walker/public_html/cgi-bin/sample-script.ss . chmod 755 sample-script.cgi chmod 755 sample-script.ssYou are now ready to view the results of your copies of these files by using the URL
(load "sample-script.ss")as is done by the cgi script. Note the output received.
/usr/local/bin/scm -q << ! (load "sample-script.ss") !and observe the output. Note that this runs scm Scheme and then issues the command (load "sample-script.ss"), just as you typed in the previous step.
One such cgi script is http://www.math.grin.edu/~walker/cgi-bin/what-i-know-script.cgi
This document is available on the World Wide Web as