130 likes | 319 Views
Chapter 33 CGI Technology for Dynamic Web Documents. There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents, these alternative forms allow computer programs to control the contents of a document dynamically.
E N D
Chapter 33 CGI Technology for Dynamic Web Documents • There are two alternative forms of retrieving web documents. • Instead of retrieving static HTML documents, these alternative forms allow computer programs to control the contents of a document dynamically. • In one form, a Web server runs an auxiliary program (CGI program) to create a document whenever a request arrives from a browser. • In the other form, a server provides the browser with a computer program (JAVA).
Three types of Web documents • Static, dynamic, and active • categorized depending on when the information in the document changes
Static Documents • content of document is determined when document is written and remains unchanged until author revises document
Dynamic Documents • document does not exist in a predefined form. • document is created by a web server whenever a browser requests the document. • When a request arrives, the Web server runs an application program that creates the dynamic document. • The server returns the output of the program as a response to the browser. • The contents of a dynamic document can vary whenever a server receives a request for the document
Active Document • consists of a computer program that understands how to compute and display values. • When a browser request an active document, the server returns a copy of the program that the browser must run locally. • Information displayed can change after the document has been loaded into a browser.
Common Gateway Interface (CGI) • Standard is used for building dynamic Web documents. • specifies how a server interacts with an application program that implements a dynamic document. • The application is called a CGI program. • CGI does not specify a particular programming language ( eg. could be C, Perl , or Unix shell (fig 33.1))
CGI program output • can be an HTML document, a plain text file, or a graphics image. • A header (eg. Content-type: text/html ) (Content-type: text/plain) consists of line(s) of text describing the document type followed by a blank line, or a header can specify that the requested document is at a different location (eg. Location: /new/bar.txt <blank line>)
CGI application support • A server that is capable of running CGI programs must be configured before it can invoke a CGI program or script. • When the a browser contacts the server and request the specified URL, the server runs the CGI program
Parameters and Environment Variables • browser can pass parameters to a CGI program via URL. • If the prefix of the URL corresponds to a CGI program, the server invokes the CGI program and passes the suffix of the URL as an argument. • The question mark character (?) in the URL separates the prefix from the suffix. • The server uses its configuration information to map the prefix to a particular CGI program. • The server passes everything after the question mark as an argument to the CGI program via environment variables instead of via command line
Environment Variables inherited by a CGI program • SERVER_NAME • contains domain name of computer running web server • GATEWAY_INTERFACE • contains version of CGI software server is using • SCRIPT_NAME • the path in the URL after the server name. • QUERY_STRING • contains information following “?” in the URL • REMOTE_ADDR • contains IP address of the computer running the browser that sent the request.
State Information • Information preserved from one invocation of a CGI program to the next • helps avoid having a user answer questions repeatedly when specifying additional requests. • CGI program saves information between requests (state information) via one of two methods • for info that must be maintained across invocations of a browser, the CGI program uses files for long term storage (fig 33.3) • for info that must be kept only while a browser is running, a dynamic document program encodes such information in URLs that appear in the hypertext links in the document(fig 33.4)
Server-Side Scripting Technologies • Alternative dynamic document technologies used when only a small portion of web page needs to be changed. • Interpreters built into web servers that can make small changes to a predefined template containing both HTML and scripts • Regular HTML passes through unchanged • Script information is replaced with output from interpreting the script • ASP, JSP, PHP, Cold Fusion