Download - Note of CGI and ASP
Index Static & Dynamic Web Pages ............................................................................................................................... 3
In early times – CGI ............................................................................................................................................. 4
A Successor of CGI - ASP..................................................................................................................................... 6
Resource ................................................................................................................................................................. 8
Static & Dynamic Web Pages "Static" means unchanged or constant, while "dynamic" means changing or lively. Therefore, static Web
pages contain the same prebuilt content each time the page is loaded, while the content of dynamic Web pages
can be generated on-the-fly(at runtime).
Standard HTML pages are static Web pages. They contain HTML code, which defines the structure and
content of the Web page. Each time an HTML page is loaded, it looks the same. The only way the content of an
HTML page will change is if the Web developer updates and publishes the file.
Dynamic Web pages, such as PHP, ASP, and JSP pages, contain "server-side" code, which allows the server to
generate unique content each time the page is loaded. It may also output a unique response based on a Web form
the user filled out. Many dynamic pages use server-side code to access database information, which enables the
page's content to be generated from information stored in the database. Web sites that generate Web pages from
database information are often called database-driven websites.
There are two primary ways to create a dynamic Web page:
* Generate the HTML tags via conventional C code. CGI, Common Gateway Interface, is this way.
* Create the Web page and insert dynamic data at run time via expansion tags(or called escape tag)
The first way requires no special handling by the Web server and may seem an attractive approach at first. But,
cause to that Web pages are hard to engineer if you cannot see the final result, so programmers need
development cycle “edit, compile, display, re-edit, re-compile, re-display”, this is very tedious.
The second approach allows much faster development cycles. Many HTML design tools such as DreamWeaver,
can be used to create Web pages in a WYSIWYG manner. All that remains, is the dynamic data that is replaced
at run time. In this way, the Web page whose full content is generated dynamically contains mini-tags that are
expanded into real tags with the dynamic data.
In general, dynamic Web pages have special file extension other than conventional ".htm" or ".html," for the
recognition of what dynamic Web page technology is adopted such as ".asp", ".php", ".jsp", etc. If it is ".htm"
or ".html," the page is probably static.
In early times – CGI Quoted from W3C (http://www.w3.org/CGI/):
“An HTTP server is often used as a gateway to a legacy information system; for example, an existing body
of documents or an existing database application. The Common Gateway Interface is an agreement
between HTTP server implementors about how to integrate such gateway scripts and programs.”
CGI is NOT a language but a simple protocol that can be used to communicate between Web forms and your
(CGI)program. The CGI program is known as CGI script or simply CGI; a CGI program could be written in a
scripting language or any programming language. CGI programs(executable scripts(with “.cgi” extension)
or binary files) are usually put in a folder named “cgi-bin”(known CGI directory) under Web server
document root directory(containing all Web pages(ex: index.html) and relevant resources(ex: pictures)).
When a request to a CGI program is received by the Web server, it runs the program as a separate process,
rather than within the Web server process. For each CGI request the environment of the new process must be set
to include all the CGI variables(environmemt variables) defined in CGI RFC specification.
The latest version of CGI is v1.1 and was specified as RFC 3875.
[PDF] http://www.potaroo.net/ietf/rfc/rfc3875.pdf
[Text] http://www.potaroo.net/ietf/rfc/rfc3875.txt
The below figure shows the basic flow of generation of dynamic Web pages through GCI.
A CGI program mainly contains three parts: standard input(STDIN), standard output(STDOUT) and
environment variable. The CGI program receives Web messages from Web server through STDIN and send
generated Web messages to Web server through STDOUT. Web clients(browsers) communicate information
with Web server through environment variable.
Reading the User's Form Input
When the user submits the form, your script receives the form data as a set of name-value pairs. The names are
what you defined in the INPUT tags (ex: select or textarea), and the values are whatever the user typed in or
Web
Client
(browser)
Web Server
HTML
page
(3) Generate
(1)
HTTP Request
(5)
HTTP Response
CGI
program
A separate
process (2) Invoke
( STDIN + EnvVar )
Return (4)
(STDOUT)
selected.
This set of name-value pairs is given to you as one long string, which you need to parse. The long string is in
one of these two formats:
"name1=value1&name2=value2&name3=value3"
"name1=value1;name2=value2;name3=value3"
The execution of a CGI program is to create a process and starting the process can consume much more time
and memory than the actual work of generating the output. So, if the program is called often, the resulting
workload can quickly overwhelm the Web server. Cause to this short point of CGI, the new way to generate
Web pages dynamically was developed, e.g. to insert expansion tags into Web pages and convert to actual data
at runtime(when being request).
A Successor of CGI - ASP Active Server Pages (ASP) is a Microsoft developed approach to allow the easy creation of dynamic Web
pages. Originally shipped in Microsoft IIS, it has now been ported to a wide variety of platforms and is
available from many vendors in commercial products.
Active Server Pages permits the scripting of dynamic data using JavaScript or any other supported scripting
language (ex:VBscript). The Web server would then evaluate the ASP script and the results are substituted into
the page replacing the original script before it is sent to the user's browser. This should be done in a one-pass
operation for maximum efficiency. By using such server-side scripting, the dynamic data to be displayed is
easily modified without recompiling the Web server.
Web pages using ASP normally(but not mandatorily) have an “.asp” extension to distinguish them form normal
HTML pages. To insert ASP tag in a Web page, the scripting code is encapsulated/enclosed using the special
marking “<%” and “%>”, also called ASP delimiter.
The below figure shows the basic flow of generation of dynamic Web pages through ASP.
<%TagName1%>
<html>
<head>
</head>
<body>
<%TagName2%>
</body>
</html>
Actual Data 1
<html>
<head>
</head>
<body>
Actual Data 2
</body>
</html>
Web server scans and
replaces escape tags
with actual data
Web
Client
(browser)
Web Server
(2) Replace
HTML Page
<%TagName1%>
<%TagName2%>
HTML Page
Actual Data 1
Actual Data 2
(1)
HTTP Request
(3)
HTTP Response
For small Web server(GoAhead, Boa) using ASP way to generate dynamic Web pages, a programmer add ASP
tags in Web page and tag handlers in Web server code correspondingly. In practice, it usually uses table-style to
store “EscapeTag - TagHandler” pair, EscapeTag is string type and TagHandler is function pointer. For
example (in C language, TagHandlerEntry is a structure),
Some Web server may provide pre-defined macro for programmer to add each entry of tag handler table.
GoAhead is one such Web server, it provides function websAspDefine() to register an ASP tag and its handler
into the tag handler table.
TagHandlerEntry AspTagHandlerTab[] = {
{ "get_timezone", get_timezone },
{ "get_date", get_date},
...
};
Resource * GoAhead WebServer White Paper
http://www.embed.com.cn/protocol/goahead/GoAhead%20WebServer%20white%20paper.doc