Tech Trends - Industry Articles
Integrating Web Sites and Databases
While Wall Street is alternating between giddy rushes and panicked sell-offs of Web stocks, the numbers of orders placed online and their corresponding revenues are skyrocketing. Fortunately, the technical side of running a Web-based business is easier to understand and somewhat less volatile than the market side. From a technical standpoint, customers need to be able to get information about a vendor's products and services, submit inquiries, select items for purchase, and submit payment information. Vendors need to be able to track customer inquiries and preferences and process customer orders. This demand for data-intensive Web sites is driving the merger between Web sites and database technologies. As commerce on the Web continues to expand, Web developers are experimenting with new technologies that promise to speed up the development and maintenance of Web sites. Companies are also discovering that intranets provide a readily accessible interface to internal databases. In this article, we shed light on popular technologies that are available for creating Web pages that interact with organizational databases.
Data Based Web Pages
In a static Web page, the content is determined at the time the page is created. When any user accesses a static page, it always displays the same information. In a dynamic Web page, the content varies based on user inputs and data retrieved from external sources. In this article, the term "data based Web pages" refers to dynamic Web pages that derive some or all of their content from data files or databases.
It is useful to separate data based Web pages from pages created using client-side scripting technologies such as JavaScript or VBScript. These technologies support tasks like data verification, displaying new browser windows, and providing animated graphics and sounds rather than interaction with file or databases.
Data based Web pages support user requests such as "I want to purchase 100 shares of Technology Inc. at $99 per share" or "What is my current checking account balance?" These user requests are usually serviced using programs running on a Web server that retrieve and display data from a file or database. Although we've included file based data retrieval within the scope of data based Web pages, this article focuses on using databases for data storage and retrieval, because of the robustness and ease of maintenance of databases compared to file based data storage schemes.
A data based Web page is requested when a user clicks a hyperlink or a "Submit" button on a Web page form. If the request comes from clicking a hyperlink, the link must either specify a Web server program or a Web page that calls a Web server program. In some cases, the program performs a static query, like "What was the Dow Jones Average for the last five time periods?" Although this query requires no user inputs, the results vary depending on when the query is made. If the request is generated when the user clicks a Web page form's "Submit" button, the Web server program usually uses the form inputs to create a query. In either case, the Web server program is responsible for formatting the query results by adding HTML tags. The Web server then sends the program's output back to the client's browser as a Web page.
Web Page Programming Options
Data based Web pages can be created using server-side or client-side processing technologies, or a combination of both. With server-side processing, the Web server receives the dynamic Web page request, performs all of the processing necessary to create the dynamic Web page, and sends the finished Web page to the client for display in the client's browser. With client-side processing, processing is done on the client workstation by having the client's browser execute a program that interacts directly with the database. Client side scripts are not able to directly interact with a database or file, but are used in data based Web page processing to validate user inputs on the client, and then send the validated inputs to the server for further processing.
Server-side processing
Most data based Web pages use HTML forms to collect user inputs and submit them to the Web server. When an HTML form is submitted to the Web server, a program running on the Web server processes the form inputs and dynamically composes a Web page reply. This program, called the servicing program, can be a compiled executable program, or a text script that is interpreted into machine language each time it is run.
Compiled Server Programs
When a user submits HTML form data for processing by a compiled server program, the Web server starts the servicing program. The program is not part of the Web server listener or administration utilities, but is an independent executable program that runs on the Web server. The servicing program retrieves the form input variables, processes them, stores the output values formatted with HTML tags in a server memory location, and then terminates. The Web server then reads the output values, and sends them back to the user's browser, where they are displayed as a Web page.
Popular languages for creating compiled server programs are Java, Visual Basic, and C++, but almost any language that can create executable programs can be used, providing the language supports commands used by one of the communication protocols that establish guidelines for communication between Web servers and servicing programs. The first communication protocol established for use with HTML forms was the Common Gateway Interface (CGI). Today, many servicing programs on Web sites still use CGI programs.
CGI relies on STDIN and STDOUT for sending form inputs to the servicing program and retrieving the servicing program's outputs. STDIN and STDOUT reference "standard in" and "standard out," which are memory buffers that originally stored keyboard inputs and screen outputs on mainframe computers. Today, these terms are still used to define a standard way of communicating inputs and outputs between different programs. The basis of the CGI protocol is that HTML form inputs are stored in the Web server's STDIN memory location, where the CGI program retrieves them. When the CGI program is done processing, it writes its outputs (which include HTML tags and text) to the Web server's STDOUT memory location. The Web server then forwards the contents of STDOUT to the client's Web browser, which displays the commands as a Web page.
A disadvantage of using CGI-based servicing programs is that each form that is submitted to a Web server starts its own copy of the servicing program on the Web server. A busy Web server is likely to run out of memory when it services many forms simultaneously. As interactive Web sites have gained popularity, Web server vendors have developed proprietary CGI based technologies to process form inputs without starting a new copy of the servicing program for every form.
These proprietary technologies for communicating with Web servers include Netscape's Netscape Service Application Programming Interface (NSAPI), and Microsoft's Internet Server Application Programming Interface (ISAPI). These technologies rely on procedures residing in dynamic link libraries (DLLs). They allow a single set of servicing procedures stored in a DLL to service multiple users without starting multiple instances of the servicing procedures. Unlike CGI programs, NSAPI and ISAPI programs are usually written in C or C++.
Server-side Scripts
Web-based applications can also use server-side scripts to create dynamic Web pages that retrieve and display database data, and modify data records. The processing architecture is the same as that used for compiled server programs, except that the Web server processing is performed using an interpreted text script rather than a compiled program.
Scripts that use the CGI communication protocol are usually written using the PERL (Practical Extraction and Report Language) scripting language. PERL contains features derived from UNIX, C, and BASIC. The current version of PERL, Version 5, handles binary and text file processing on a variety of operating system and Web server platforms. The language itself is terse, and many operations and commands are specified with one- or two-character commands. Special characters such as $, #, %, and / are heavily used to indicate data types and operations.
PERL has functions for manipulating text strings and processing files that have descriptive names, and make the code easier to understand and work with. Although it is possible to write well-documented and maintainable PERL scripts, the language encourages cryptic shortcuts, so PERL scripts can be difficult to understand and maintain.
Another approach for creating server-side scripts is provided with Microsoft's Active Server Pages (ASPs). (The default scripting language for an ASP is VBScript, which is similar to Visual Basic, but ASPs can also be created using JavaScript.)
When the ASP is submitted to a Microsoft Web server, the file's ASP extension signals the server to process the file as an ASP, and then return the outputs to the user as a formatted Web page. Script delimiter tags (<% … %>) instruct the browser which commands are to be processed as code rather than displayed as Web page text and tags. As processing proceeds, retrieved data values might be displayed on the current Web page, or might be passed as parameters to a different Web page that is called within the script code. A similar approach is used by Netscape's LiveWire technology, which uses JavaScript as the default scripting language.
Client-Side Processing
Client-side Web page processing can be achieved using compiled programs that are downloaded and subsequently installed and executed on the client workstation, or by creating scripts within the HTML Web page commands that are interpreted by the client browser.
Read the book:
Downloading and Running Compiled Programs on Client Workstations
When a user clicks a hyperlink on a Web page that is associated with a compiled client-side program, the user's browser must have the ability to run the executable program file. This program interacts with the user and sends and retrieves data from a database server as needed. Popular technologies for creating programs that users can download from Web sites and install on their computers include Java applets and Microsoft ActiveX documents.
Java applets are self-contained Java programs that run in a generic Java runtime environment supplied by most Web browsers. For security reasons, Java applets can receive data from a Web server and send data to a Web server, but cannot read data from or write data to any files on the user's workstation. Java applets are intended to run uniformly on any operating system and with any Web browser. However, at the present time, the Java run time environment is implemented inconsistently in different browsers, and even within different versions of the same browser. This makes it difficult to create a Java applet that will run identically within all browsers.
ActiveX programs can be created using many different programming languages as long as those languages support Microsoft's ActiveX data protocols. Unlike Java applets, ActiveX is a Microsoft-specific technology, and must run on the Windows operating system and in a Microsoft browser.
Client-side Scripts
In a client-side script, uncompiled code written in languages such as JavaScript or VBScript is embedded in an HTML document along with the static HTML text. This code is placed within delimiter tags to indicate to the user's browser that this text is code rather than Web page text. If the user's browser has the capability of recognizing and interpreting the code, it is then processed. If the browser cannot recognize and interpret the code, the script code is displayed as text on the Web page unless the script author has enclosed the code in an HTML comment.
Client-side scripts cannot be used to interact with a remote database, but are often used to validate user inputs entered on HTML forms that are submitted for processing by a server-side program. For example, a script running on the client workstation might check the inputs that a user submits to a Web page to make sure the user entered all required data and entered appropriate data values. This approach avoids transmitting inputs to the Web server that are incomplete or have errors, and offloads error checking and handling from the Web server program to the client workstation. Client-side scripts can also be used to create advanced Web page features such as an image map that allows the user to move the mouse pointer over a graphic image and click to access different Web page links, a new browser window to display an alternate Web page, a timer to display a graphic or play a sound, or "cookies" to store data on a user's computer about his or her actions while browsing a Web page.
The most commonly used client-side scripting language is JavaScript, which is supported by Netscape Navigator, Microsoft Internet Explorer, and most other browsers. (JavaScript can also be used for server-side processing using Web-server specific languages derivatives. A version of JavaScript called LiveWire can be used on Netscape Web servers for server-side processing of form inputs. A Microsoft-specific version of JavaScript called Jscript can be used in Active Server Pages on Microsoft Web servers.) JavaScript's syntax is similar to C, C++, and Java, but technically, functionally, and behaviorally, JavaScript is very different than these languages.
This article provides an overview of current Web programming technologies. Other Web/database technologies exist and continue to emerge, but the underlying concepts of server-side and client-side processing and their implications have remained constant in today's rapidly evolving Web development environment.
