Database Reference
In-Depth Information
18.1. Basic Principles of Web Page Generation
Problem
You want to produce a web page from a script, not write a static page manually.
Solution
Write a program that generates the page when it executes. This gives you more control
over what is sent to the client than when you write a static page, but may also require
that you provide more parts of the response. For example, it may be necessary to write
the headers that precede the page body.
Discussion
HTML is a markup language—that's what the “ML” stands for. HTML consists of a mix
of plain text to be displayed and special markup indicators or constructs that control
how the plain text is displayed. Here is a very simple HTML page that specifies a title
in the page header, and a body containing a single paragraph:
<html>
<head><title> Web Page Title </title></head>
<body>
<p> Web page body. </p>
</body>
</html>
It's possible to write a script that produces that same page, but doing so differs from
writing a static page. For one thing, you're writing in two languages at once: the script
is written in your programming language, and the script itself writes HTML. Another
difference is that you may have to produce more of the response that is sent to the client.
When a web server sends a static page to a client, it sends a set of one or more header
lines first that provide additional information about the page. For example, an HTML
document is preceded by a Content-Type: header that lets the client know what kind
of information to expect, and a blank line that separates any headers from the page body:
Content-Type: text/html
<html>
<head><title> Web Page Title </title></head>
<body>
<p> Web page body. </p>
</body>
</html>
To indicate a particular character set encoding, add it to the Content-Type: header. For
good measure, specify it in a <meta> tag as well:
Search WWH ::




Custom Search