|[ LiB ]|
A static web page is one that's completely created in advance, with all text and images in place, and housed on a web server to await a visitor coming to look at it. A dynamic web page , in contrast, contains placeholders for content that the server inserts at the moment a visitor requests the pageat runtimealong with instructions to the server on how to construct the completed page. A look at how web pages are processed between the server and the browser will show you how this works.
Figure 21.1 shows the typical set of events in the life of a static web page. The page exists on the server. When a visitor clicks a link or types a URL in the address field, the browser sends a request in the form of the desired URL to the web server. The server software then finds the page and responds by sending it back to the browser. This is called the request-and-response model . The request is an HTTP request, using the http:// protocol to begin the URL; the web server software is also called the HTTP server .
Dynamic data can enter into this equation in three main ways:
Server-side includes (SSIs)
Database connectivity using application servers
Although the purpose of this section is to show you the third method, all three are covered here so that you can see how they relate.
The simplest kind of dynamic contentand the easiest to understandis the server-side include , or SSI. An SSI is a placeholder that sits in an HTML document, containing instructions to the server to replace it with some dynamically generated data. The data inserted can be anything from a chunk of predefined code to the current date or time to information collected from processing a script or querying a database. The code for an SSI might look like any of the following:
<!--#include virtual="mydata.html" --> <!--#echo var="DATE_LOCAL" --> <!--#exec cgi="/cgi-bin/sample_script.pl" -->
The HTML document containing an SSI is saved with a special filename extensiontypically .shtm or .shtmlto alert the server that SSIs are present.
For more on using SSIs in Dreamweaver, see the section "When a Library Item Should Be a Server-Side Include" in Chapter 20, "Site-Wide Content with Templates and Libraries."
Figure 21.2 shows the web page request-and-response process for an HTML page using SSIs. When the server receives a request for an SHTML document, it responds by finding any embedded SSIs in the page, executing their instructions, and inserting the resulting data into the document, which it then passes to the browser. Usually this involves substituting some real data (such as the date or time, or even the contents of another file stored on the server) in place of the SSI placeholder code.
A more truly dynamic web page can be created using CGI scripting to process browser requests and respond by saving user input, delivering web pages with filled-in placeholder content, and even building pages at runtime from collections of code snippets. For this discussion, you need to know only that CGI scripts (usually written in Perl) are stored in a special folder on the web server, generally called cgi-bin . When a user fills out a form, the form action might contain the URL of a CGI script, like this (the URL is in bold):
<form name="theForm" action= "http://www.domain.com/cgi-bin/ myscript.cgi" method="post">
Clicking the form's Submit button causes the browser to request the specified script, passing it the form variables as part of the URL or as an attached posting. Figure 21.3 diagrams the ensuing request-and-response process. The web server knows , because of the extension of the file that is called (.cgi or .pl, depending on how the server software is set up), that the requested page should not just be downloaded back to the browser. Instead, it finds the script and executes it. The script might perform a simple task such as emailing user input to a designated address, or it might execute much more complex operations such as performing calculations on user data, talking to a database, and so forth.
The third and most powerful way to create dynamic web pageswhat this section of the book is all aboutis using databases to provide content and special software modules called application servers to construct pages at runtime. Figure 21.4 diagrams the basic response-and-request process for this kind of dynamic content.
The general procedure is as follows :
That's how the process works. Now it's time to take a look at who all the players are and how they all fit together.
Obviously, setting up a database-driven website involves a lot of variables and requires learning all sorts of new names and technologies. The following sections examine the pieces of the puzzle one at a time.
The web server itself is a computer, using some version of Windows or Unix/Linux (including Mac OS X) as its operating system, running special web software for processing HTTP requests. The term web server in a discussion of dynamic sites usually refers not to the computer itself but to the server software. This software is also called the HTTP server to distinguish it from the application server (discussed later in this chapter). The most common server software is described in the following sections.
Created and maintained by the Apache Software Foundation, Apache is the most popular server software today, installed on more than 50 percent of web servers worldwide. Apache is open -source software and therefore is either free or very cheap to obtain. It's stable and powerful, and it runs on just about any operating system.
Microsoft's Internet Information Server (IIS) software is second only to Apache in popularity. It's powerful and flexible, although as a Microsoft product it runs only on servers using the Windows operating system (NT, 2000, or XP).
The heart of the data-driven website is, of course, the database. For the system to work, it must have a database, and the database must reside on the web server (or on a computer accessible to the web server). To create the database and work with it offline, you must have access to a piece of software called a database management system (DBMS). To make the database part of an online system, a DBMS must reside on the server.
To keep things simple, this discussion focuses on all the components of server-side data processing as if they were stored on one server computer. In fact, multiple networked computers might be involved. This won't change how the system works, however.
To author database-driven web pages online, you don't need to be a database expert. However, you do need to know at least how databases store data, how to ask them questions and give them commands, and how to use drivers to communicate with them.
Databases store information in tables, as a series of fields ( columns ) and records (rows). Figure 21.5 shows a simple table structure at work. Adding a new customer to the database adds a new record, or row. Adding a new field, or column, means storing one more piece of information about each customer. This table structure is called hierarchical data storage .
Hierarchical information storage is fine as far as it goes, but it doesn't go far enough to handle complex information. The more-sophisticated databasesthe ones generally used with data-driven websitesare relational databases , run by relational database management systems (RDBMSs). Relational databases offer the following features:
Multiple tables A relational database stores information in a series of tables, related by common key fields. Figure 21.6 shows the same information table shown in Figure 21.5, but with a second and third table added to store different kinds of data.
Primary and foreign keys Keys create the relationships between the tables. Each table must contain one field designated as the primary key field , which contains a unique entry for each record. This lets you call up a specific record by searching for the value in this field. Each table relates to the other tables by having its primary keypresent in the other table as a foreign key. As the dotted lines in Figure 21.6 show, the Customer ID and Product No. primary keys become foreign keys in the Order table, establishing the relationships between the tables.
A database is useful only if you can find, update, and analyze information in it. You do this by using the database management system to query the database. How many people have ordered product J-9995 since January of last year? Did more or fewer people order the item the year before? What is the most expensive item ordered since March? When was the last time Moe Howard ordered anything? Sort the customer database by name, zip code, or state. Raise all prices in the product database by 5 percent. The standard language used for querying databases is Structured Query Language (SQL). Hence, database queries also are called SQL statements .
Application servers communicate with database management systems through drivers pieces of software that define how to move information into and out of databases. The most common driver formats are Microsoft's Open Database Connectivity (ODBC) and Sun Microsystems' Java Database Connectivity (JDBC). A database management system that can connect using one of these formats is said to be ODBC-compliant or JDBC-compliant.
To function as part of an online system, a database management system must be a relational database, must be able to run in whatever operating system is required by the server, must understand SQL statements, and must be compliant with ODBC, JDBC, or some other standard driver format. This section describes some common database management systems for online use.
Microsoft Access , the most popular database program for general business use, is often used for small to mid-size online databases. Access isn't the most powerful DBMS. Its main limitation for online use is that it cannot accept large numbers of users trying to access it simultaneously . It is reasonably priced, however, and easily available as part of Microsoft Office. As a Microsoft product, it runs only on Windows servers.
SQL Server is the big brother of Access, intended for large-scale sites with huge amounts of data and a significant number of simultaneous hits. This powerful program is expensive, and learning it is not for the faint of heart. Like Access, it runs on Windows only.
MySQL , a DBMS that has its roots in Unix, is a good alternative to Access if you are on a tight budget or are not working on Windows. It doesn't have the same multiple-access limitations as Access, and it's famous for its speed and stability and for being able to handle large amounts of data. But it is missing some of Access' advanced features, such as stored procedures. In its basic form, MySQL uses a command-line interface, so it might seem intimidating at first. However, several free GUI MySQL interfaces are available. Its learning curve is surprisingly gentle compared with Access. Depending on how you use it, it's either free or cheap. It runs on Windows, Unix, Linux, or Mac OS X.
PostgreSQL , sort of a big brother of MySQL, is the most advanced open-source DBMS available. It runs in Unix-based environments, including Linux and now Mac OS X. For the non-Microsoft crowd , it's a good alternative to SQL Server.
Oracle , from Oracle Enterprises, is the most powerful database management system available. It's also not a program for small businesses or anyone on a tight budget. It's very expensive, and it comes with a steep learning curve and very expensive authorized training. Oracle runs on Linux, Unix, and Windows operating systems.
For more information on Access and SQL Server, visit www.microsoft.com. To learn about (and download) MySQL and PostgreSQL, visit www.mysql.com and www.postgresql.org. To learn about Oracle, visit www.oracle.com.
Databases, and database management systems, are a big topicbut they're only half of the story. The application server software functions as middleware , allowing communication between the browser and the DBMS. Choosing an application server is like getting married. You (and your client, and your company) will be up close and personal with this software on a daily basis for a long time. You'll use the application server language to write your pages. You'll be limited by its limitations and empowered by its strengths.
Which web server, database, and/or application server should you choose? Unless you're in charge of your web server's configuration, these decisions probably aren't entirely up to you. Whoever hosts your site will have certain technologies available. If you're shopping for a host, it's a good idea to learn what technologies each host offers, and how those options fit your needs, before choosing one.
Macromedia's ColdFusion has become a very popular alternative to ASP, largely because it uses a tag-based , rather than script-based, means of communicating with the DBMS. The core of ColdFusion functionality is ColdFusion Markup Language (CFML). Page elements can also be built using the CFScript scripting language.
The application server portion of ColdFusion is called ColdFusion Server . It operates on servers running Windows, Linux, HP-UX, or Solaris, and it must be purchased separately from any web server software. Because it is available only through commercial licenses, ColdFusion might not be the most immediately attractive choice for small businesses, but the speed of page construction possible using CFML makes the long-term development costs very reasonable. To learn more about ColdFusion, visit http://www.macromedia.com/software/coldfusion.
PHP (the recursive acronym for PHP: Hypertext Preprocessor) is a popular open-source alternative to commercial systems. Its commands are script-based, written in PHP scripting language.
PHP is available freely or cheaply, depending on its intended use. It has a large and friendly user community supporting it, but no commercial guarantees behind it. PHP works with Apache and Microsoft IIS web servers and on Unix, Windows, and Mac OS X operating systems. Unlike the other server technologies, PHP is database-specific . Not all installations of PHP work with all DBMSs. Dreamweaver MX 2004 supports PHP for use with MySQL. To learn more about PHP, visit http://php.net/.
According to Microsoft, the .NET framework, which includes ASP.NET, is the new face of dynamic web development. Programs and scripts can be written in several languages, including Managed C++, C#, JScript, and Visual Basic, and they can be executed server-side or client-side. Live data pages can also be programmed to tie in with Microsoft's COM technology. ASP.NET offers many of the advantages of using Java/JSP (see the next section), but strictly within the Microsoft fold. ASP.NET runs only on IIS web servers, and of course only on servers running the Windows OS. To learn more about ASP.NET, visit http://www.microsoft.com/net/.
JSP , or JavaServer Pages, is (as its name implies) a Java-based alternative to both ASP and ColdFusion. The application server is in the form of an appletcalled a container that resides on the server. Popular JSP containers include several commercial entries, such as Macromedia's JRun and IBM's WebSphere, as well as the popular open-source Tomcat. Generally, JSP is favored by Java programmers. It's definitely not for novices. To learn more about Java development, including JSP, visit http://java.sun.com.
ASP is an old technology, being replaced by ASP.NET. JSP generally is not used except by Java developers. This book focuses on ColdFusion, PHP, and ASP.NET.
|[ LiB ]|