Saturday, December 8, 2007

Dynamic Web Site Basics

Dynamic Web Site Basics

Setting aside, for a moment, the specifics of the Newland Tours site, in the preceding lessons you explored several concepts that are critical to dynamic site development. One of these is the separation of logic and presentation. The site logic at this point is handled exclusively by XHTML, while the presentation is handled by the cascading style sheet. You have also explored the concept of merging two different documents (an HTML page and a CSS) on the fly to create something different than either of the two source documents alone. These concepts are fundamental to creating dynamic Web sites.

To understand these interactions, and to prepare you for the tasks ahead, let's take a moment to analyze the relationship among the three different major sources of information that make up every Web page: the content (text, images, etc.), the logic (the document hierarchy, such as headings and body text), and the presentation (the colors, font sizes, positioning, and other cosmetic effects).

In earlier versions of HTML, text, markup, and presentation code all exist in the same place: the HTML document itself. In a meaningful way, the document that a developer creates on her or his hard drive is the same as the document viewed in a browser by the site visitor. This simple relationship is shown in the following figure.


As a result of the upgrades you made in Lessons 2 and 3, the relationships have changed: You have separated a document's presentation from its logic and content. Presentation information is now stored in the CSS. Document content is stored as text within the XHTML markup, which also provides the document logic. Only when the XHTML document and the CSS are merged is the "real" page created. This new relationship is represented in the following figure.


Beginning with this lesson, you are going to add yet another layer of sophistication to this relationship—one that's more profound and more powerful even than migrating from HTML to XHTML and CSS. Specifically, when you add database content to the site, you will separate the content from the logic. What this means is that all three levels—presentation, logic, and content—are quasi-independent of each other, which means you can make radical changes to one without needing to make changes to another. The relationship—and the basic blueprint for the rest of the book—is shown in the following figure.


HTML cannot separate content from document logic. Even in its fifth major revision as XHTML 1, HTML is ultimately intended to mark up a plain text document. It cannot process scripts, evaluate expressions, do math, interact with a database, or send and receive information to or from a user. Yet separating logic from content requires, at times, each of these abilities and more. To accomplish these tasks, you need to give HTML some help, and this is where server-side technologies such as Microsoft ASP and Macromedia ColdFusion MX fit in.

Server technologies like ASP and ColdFusion (and there are others, including JSP, PHP, and ASP.NET) are able to handle programming tasks such as evaluating expressions, doing math, and processing scripts. In addition, they are capable of interacting with data sources, including databases, structured text files, and in some cases XML data. They also have special abilities that pertain only to the Web, such as the ability to collect data sent by the user and control the information that gets sent back to the user.

But there's a catch. Browsers are limited to handling HTML, CSS, and JavaScript—they don't understand ASP or ColdFusion code. Whatever the server sends to the browser has to be in standard HTML. All ASP and ColdFusion scripts must be processed on the server and output as standard HTML before they get sent to the browser.

To put it more plainly, to view a page with dynamic content, you need to run the page through a server capable of processing the code. This is in contrast to standard HTML pages, which you can view directly in a browser, regardless of whether they go through a server. You can open Internet Explorer or Netscape and browse to any of the HTML pages in the Lesson04/Start folder, and they will display as expected. If you attempt to browse to the pages in the Lesson04/Complete folder, you'll discover that the pages don't open (or they open in Dreamweaver MX, rather than in the browser). The browser sees code it doesn't understand, and refuses to open the file. This is why, in Lesson 1, you viewed the final version of the site at allectomedia.com, rather than from the CD.

Choosing a Server Model

You know already that there are several common server-side languages. This begs the question (often asked by those new to dynamic site development), "which server model should I use?" The following list summarizes the main functions, pros, and cons of each:

Active Server Pages (ASP): ASP is a Microsoft technology that ties together its IIS (Internet Information Services for Windows 2000 and XP) or PWS (Personal Web Server for Windows 98) servers with VBScript (Visual Basic Script) for dynamic Web site development. (You can also use Microsoft's implementation of JavaScript, JScript.) ASP is free and built into all IIS and PWS servers, which means that virtually all Windows users can develop ASP sites for free with little configuration. Its code, VBScript, can be somewhat daunting for those with little to no programming experience. ASP is currently being replaced with Microsoft's much-ballyhooed ASP.NET (see below).

ColdFusion: ColdFusion is Macromedia's server technology. Its tag-based syntax is generally much easier to use than VBScript, and it certainly requires fewer lines of code. Most designers find it the most accessible of all the server models. Newbies aside, ColdFusion is a powerful language that makes dynamic site development rapid. The disadvantage to ColdFusion is that it is not free, though the boost to productivity it affords usually means it pays for itself.

PHP Hypertext Processor (PHP): An acronym within an acronym, PHP is a fast-growing server model for a variety of reasons. As an open-source solution, it is free and ties in well with other excellent open-source products, including the Apache Web server and MySQL database management system. Its code is comparable in difficulty to that of ASP. One disadvantage—and this is true of many open-source products—is that setting up and configuring PHP-Apache-MySQL can be difficult.

ASP.NET: The Web authoring portion of the .NET phenomenon, ASP.NET is a powerful new technology that holds a lot of promise for rapid, powerful Web development. Like its predecessor ASP, it runs on any Microsoft IIS server that has the free .NET extensions installed. But ASP.NET is conceptually different from ASP, ColdFusion, and PHP. ASP.NET meets the needs of desktop application programmers, in some ways at the expense of traditional Web programmers. Whether you know only HTML, or you have experience with JavaScript or even ASP, you will need to do some adjusting to work with ASP.NET effectively.

JSP: JSP is the Java-based solution to dynamic Web site development, requiring a Java server (such as a J2EE server) to interpret the code. JSP is fast, providing impressive response times. But its code, once again, is daunting for those new to dynamic Web site development.

This book provides coverage of ASP and ColdFusion. However, this is not an ASP or ColdFusion book. The book is designed to initiate readers into the concepts and practices of building dynamic Web sites using Macromedia Dreamweaver MX. You will learn lots of code and coding concepts along the way, and you will also make use of Dreamweaver's server behaviors to speed up and simplify development. When you are done, you will have a solid sense of what's possible, how several different technologies merge to create dynamic pages, and how to plan and build sites that use these technologies effectively. Most likely, you will not in the end be an ASP or ColdFusion expert per se, but you should be able to get an ASP or ColdFusion book at that point and understand it well enough to push forward and develop ambitious Web projects.

Having summarized the advantages and disadvantages of the various server models, I'll let you in on a secret. Web developers seldom choose based on rational criteria, such as which model fits their needs better than another. I certainly have rarely had that opportunity. In reality, the choice is usually driven by the available technology, your budget, the technologies used in an existing site, and the skills and experience of the available human resources. Going a step further, unless you develop for one organization and one organization only, and you intend to stay there for a very long time, you probably don't have the luxury to learn just one server-side language. Due to circumstances relating to my work situation, I initially learned ColdFusion and ASP simultaneously, because each was required for a different project I was working on.

No comments: