Page

2.2.2- Server-Side Scripting and Client-Side Scripting

Created by Brendan Doss.
Last Updated by Jim Minatel.  

<< 2.2.1- Which Scripting Language to UseChapter22.2.3- Server-Side Scripting >>

Server-Side Scripting and Client-Side Scripting

What difference does the introduction of scripts make to the way the page is processed? For the most part, our model of the browser making a connection to the web server, sending a request, receiving a response and then interpreting the received HTML to construct a web page still holds true.

 

The only difference comes when, in the act of preparing a page to be sent to the browser, the server comes across a script. The first thing that the server must do is identify which machine is responsible for processing the script. This is an important point because, when we write a script, we can choose whether it is to be processed by the server or by the browser. Let's make this difference more precise:

 

  • A script that is interpreted by the web server is called a server-side script. A server-side script is an instruction set that is processed by the server, and which generates HTML. The resulting HTML is sent as part of the HTTP response to the browser.
  • A script that is interpreted by the browser is called a client-side script. A client-side script is also an instruction set, but it is not processed by the web server. Instead, it is sent to the browser (as part of the HTTP response) and is processed by the browser; the result is then displayed by the browser on the monitor.
So we can complete the picture that we began in Chapter 1, by adding one more step to take care of the client-side scripts:

 

543636_pg65.jpg

As we'll see, server-side scripting and client-side scripting each offer their own advantages. We'll have a look at client-side scripts later in the chapter, in order to put ASP (and other server-side scripting techniques) into context. First, let's take a look at some more ASP and other server-side scripts.

Identifying a Script

We've just been talking about how the web server identifies on which machine a script must be processed. But how do we identify a script, when it is embedded in a small or large amount of pure HTML? In fact, we already partially answered this question in Chapter 1 – because ASP (which is destined to be processed on the web server) will be enclosed in special <%%> tags, like this:

 

In Webserverland, the time is exactly <%= Time %>

 

Here, everything contained within the <% and the %> is assumed to be ASP, and is sent to the ASP script host for processing.

 

But there are other kinds of scripts, which are not ASP code, but which still need to be distinguished from the HTML and text in which they are embedded. For this reason, HTML provides a special tag – the <SCRIPT> tag:

 

<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>

Response.Write Time

</SCRIPT>

 

Anything that lies between an opening <SCRIPT> tag and a closing </SCRIPT> tag is dispatched for processing to the appropriate script engine, according to the instructions given by the SCRIPT tag's attributes. We'll use this to identify both client- and server-side scripts, as you'll see in the examples that follow.

<< 2.2.1- Which Scripting Language to UseChapter22.2.3- Server-Side Scripting >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |