Basics of Dynamic Sites

[ 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.

How Static Web Pages Work

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 .

Figure 21.1. The standard request-and-response process for static web pages.


How Dynamic Web Pages Work

Dynamic data can enter into this equation in three main ways:

  • Server-side includes (SSIs)

  • CGI scripts

  • 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.

Server-Side Includes (SSIs)

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.

Figure 21.2. The request-and-response process for web pages that use SSIs.


CGI-Scripted Documents

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.

Figure 21.3. The request-and-response process for web pages that access CGI scripts.


Application Servers and Database Connectivity

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.

Figure 21.4. The request-and-response process for web pages built using an application server and database connectivity.


The general procedure is as follows :

  1. The browser sends an HTTP request consisting of the URL for a document with a filename extension such as .asp, .aspx, .cfm, .php, or .jsp.

  2. The web server software recognizes the extension, finds the requested page, and activates the application server. This might be the Active Server controls built into Microsoft web servers, ColdFusion Server, Tomcat Java server, or the PHP module.

  3. The application server reads the document and either executes any scripts or interprets any custom tags it finds. These scripts and tags usually contain requests for some database information (such as "Place the contents of the Product Name database field from the Widget International database here") or instructions to change the database information (such as "Add John Smith to the Username database field in the Books Online database").

  4. The application server sends these requests and instructionscollectively called queries to a database management system such as Access or MySQL, which finds the appropriate database and performs the requested actions. If any information was requested, it's sent back to the application server.

  5. The application server constructs an HTML-formatted page containing the requested information formatted according to the instructions in the originally requested document, and sends the whole lot back to the web server.

  6. The web server returns this page to the browser.

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.

Who's Who and What's What in the World of Dynamic Data

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 Server OS and HTTP Server Software

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.

Apache

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.

Internet Information Server

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 Database

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.


Hierarchical Data Storage

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 .

Figure 21.5. Data stored in a hierarchical, or table, structure.


Relational Databases

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.

    Figure 21.6. Three related tables storing customer, order, and product 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.

Queries and SQL Statements

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 .

Drivers (ODBC and JDBC)

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.

Standard DBMS Programs

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.


The Application Server (Middleware)

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.

ColdFusion

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

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/.

ASP/ASP.NET

ASP (Active Server Pages) is Microsoft's basic application server. ASP is not an independent program or software module, like other application servers are. Rather, it's a functionality built into the Microsoft web server software (IIS). The language is script-based, using VBScript or JavaScript to formulate database queries and construct pages based on the results. Many developers still use ASP for less-complex websites , but it is being supplanted by the much more powerful ASP.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

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 ]


Macromedia Dreamweaver MX 2004 Demystified
Macromedia Dreamweaver MX 2004 Demystified
ISBN: 0735713847
EAN: 2147483647
Year: 2002
Pages: 188
Authors: Laura Gutman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net