In web applications, there are usually at least two computers involved: a client computer that requests a particular web page, and a server computer that processes that request and serves the page back to the client. (See Figure 16-1.)
In the diagram in Figure 16-1, we can see the process of requesting a web page. Recall that we looked at this briefly in Chapter 1. It starts on the client machine with our website visitor entering or choosing a Universal Resource Locator (URL) in a browser. The URL tells the browser which server machine on the Internet to request the web page from, together with a path for the server directory that the web page is located in and of course the file name of the web page.
The browser then sends a request for the page to the server indicated in the URL. If we supply only a server name, or a server name and path to a directory, the server sends the default page, if there is one, for that directory which will be passed back from the server. The server machine receives the request and then finds this page before sending it back to the client computer. The client computer receives the page and passes it to the browser, which then displays it, executing any JavaScript code embedded inside the page.
So far in this book, we have been dealing with client-side JavaScript. This is simply JavaScript code that executes in the browser running on the client computer. However, server machines are not just dumb computers that find a file and pass it back to the client. They can also do their own processing before passing the page to the client. Any processing done by the server machine before the web page is sent back to the client is referred to as server-side processing.
Server-side processing can involve a variety of tasks, such as processing information sent by the user in a web page's form, accessing a database to retrieve or store information, running a program on the server to check credit card details before telling another computer to send goods to a customer, and even sending e-mails. With the right components installed, a server can undertake a vast range of tasks.
So where does JavaScript fit into all this? Well, most web servers support the embedding of script into a web page that is then processed by the server itself before the page is sent to the client computer. One of the scripting languages that can be embedded in pages on a Microsoft web server is JavaScript. However, Microsoft web servers are not the only web servers we can use. There are many, many different web servers available from companies, such as IBM, Sun, and Netscape to name just a few. One of the most popular web servers is Apache on the Linux operating system. Many of these web servers have their own scripting languages, such as PHP, which provides functionality to JavaScript's. Some, such as Netscape's Enterprise Server, also support JavaScript itself, and others, such as Apache, can have JavaScript support installed.
We know that JavaScript is just a programming language and that it needs an environment to run in for it to be useful. When we were writing JavaScript client-side code, that environment was the web browser and the Browser Object Model (BOM) it makes available. Server-side scripting also needs to run in an environment, this time one provided by the server itself. On Microsoft servers, this environment is called Active Server Pages (ASP). Just as the browser made the page available via objects, such as the window object and document object, ASP also enables interaction with the server via objects. The good news is that the knowledge you'll gain here about ASP and server-side scripting can also be used on other web servers, such as those that run on Unix and Linux operating systems.
Before we start looking at the ASP objects, we need to install a server. Normally the web server and user's browser would be on different machines, but there's no reason they can't be on the same machine. In fact, this is very handy for development purposes.