| << 1.1.0- What is a Dynamic Web Page? | Chapter1 | 1.1.2- Using Dynamic Web Pages >> |
Static Pages vs Dynamic Pages
OK, so let's think for a moment about how a static, pure-HTML page finds its way onto a client browser:
1. A web author writes page composed of pure HTML, and saves it within an .htm file
2. Sometime later, a user types a page request into their browser, and the request is passed from the browser to the web server
3. The web server locates the .htm page
4. The web server sends the HTML stream back across the network to the browser
5. The browser processes the HTML and displays the page
We use the term web server
to refer to the software that manages web pages and makes them available to
'client' computers – via a local network or via the Internet. In the case of
the Internet, the web server and browser are usually on two different machines,
possibly many miles apart.
However, in a more local situation we might set up a machine that runs the web
server software, and then use a browser on the same machine to look at
its web pages. We'll talk more about web servers later in this chapter, and
throughout the book.
Static, pure-HTML files like Welcome.htm file make perfectly serviceable web pages. We can even spruce up the presentation and usability of such pages by adding more HTML to create frames and tables. However, there's only so much we can achieve by writing pure HTML, precisely because their content is completely determined before the page is ever requested.
The Limitations of Static Web Pages
|
For example, suppose we want to enhance our Welcome page – so that it displays the current time or a special message that is personalized for each user. These are simple ambitions, but they are impossible to achieve using HTML alone. If you're not convinced, try writing a piece of HTML for a web page that displays the current time, like this:
|
|
As you type in the HTML, you'll soon realize the problem – you know that the user will request the page sometime, but you don't know what the time will be when they do so! Hard-coding the time into your HTML will result in a page that always claims that the time is the same (and will almost always display the wrong time).
In other words, you're trying to write pure HTML for a web page that displays the time – but you can't be sure of the exact time that the web page should display until the time the page is requested. It can't be done using HTML alone.
Since we can't create our page by saving our hard-coded HTML into a file before the page is requested, then what we need is a way to generate the HTML after the page is requested.
Dynamic Web Pages
In other words, we need to replace the hard-coded HTML source with a set of instructions, which will be used to generate HTML for the page at the time the user requests the page. In other words, the page is generated dynamically on request. So our set of five steps now becomes six:
1. A web author writes a set of instructions for creating HTML, and saves these instructions within a file
2. Sometime later, a user types a page request into their browser, and the request is passed from the browser to the web server
3. The web server locates the file of instructions
4. The web server follows the instructions in order to create a stream of HTML
5. The web server sends the newly-created HTML stream back across the network to the browser
6. The browser processes the HTML and displays the page
So the process of serving a dynamic web page is only slightly different from the process of serving a static web page – there's just one extra step involved (Step 4). But the difference is crucial – the HTML that defines the web page is not generated until after the web page has been requested. For example, we can use this technique to write a set of instructions for creating a page that displays the current time:
<HTML>
<HEAD><TITLE>The Punctual Web Server</TITLE></HEAD>
<BODY>
<H1>Welcome</H1>
In Webserverland, the time is exactly
<INSTRUCTION: write HTML to display the current time>
</BODY>
</HTML>
In this case, we can compose most of the page using pure HTML. It's just that we can't hard-code the current time; instead, we can write a special code (which would replace the highlighted line here) that instructs the web server to generate that bit of HTML during Step 4, at the time the page is requested.
We'll return to this example later in the chapter, and we'll see how to write the highlighted instruction using ASP.
We could extend the notion of dynamic pages even further, by adding another step (between Steps 5 and 6 above) – in which we include more instructions that are carried out by the browser (not by the server). For the purpose of this chapter, we will not consider this type of 'dynamic page' – but we will return to it in Chapter 2 .
| << 1.1.0- What is a Dynamic Web Page? | Chapter1 | 1.1.2- Using Dynamic Web Pages >> |

RSS


