ASP   «Prev  Next»

Lesson 2 Server-side scripting
ObjectiveCompare server-side and client-side scripting.

Compare Server-side and Client-side Scripting

If you develop Web pages or applications, Microsoft's ASP performs two very important tasks:
  1. It lets you run scripts on the Web server instead of the client, a user's browser; and
  2. It allows you to incorporate scripting commands as a part of your HTML pages.

Script Language Comparisons

If you have already written scripts in JavaScript, VBScript , or Perl, you will recognize that ASP pages look very similar. The key difference between scripts you might have written before and those you write with ASP is that ASP scripts run on the Web server, not through the user's browser program. When you design a Web application, you can choose to use client-side techniques ,in which scripts are run through the user's browser, or server-side techniques, in which scripts are run from the Web server, or a combination of the two. The most common client-side technologies are Java, VBScript, JavaScript, and JScript. The most common technologies on the server side are:

SEMrush Software

Server-side Scripting

The first popular API for application gateways was the Common Gateway Interface (CGI). CGI is a standardized set of interfaces that web servers use to launch programs in response to HTTP requests for special URLs, collect the program output, and send it back in HTTP responses. Over the past several years, commercial web servers have provided more sophisticated interfaces for connecting web servers to applications. Early web servers were fairly simple creations, and the simple approach that was taken for implementing an interface for gateways has stuck to this day. When a request comes in for a resource that needs a gateway, the server spawns the helper application to handle the request. The helper application is passed the data it needs. Often this is just the entire request or something like the query the user wants to run on the database.It then returns a response or response data to the server, which vectors it off to the client. The server and gateway are separate applications, so the lines of responsibility are kept clear.

(CGI) Common Gateway Interface

The Common Gateway Interface was the first and probably still is the most widely used server extension. It is used throughout the Web for things like dynamic HTML, credit card processing, and querying databases. Since CGI applications are separate from the server, they can be implemented in almost any language, including Perl, Tcl, C, and various shell languages, and because CGI is simple, almost all HTTP servers support it. CGI processing is invisible to users and from the perspective of the client, it is just making a normal request. It is completely unaware of the hand-off procedure going on between the server and the CGI application.
CGI, the Common Gateway Interface, was developed at the University of Illinois' NCSA, the National Center for Supercomputing Applications. CGI allows executable programs running on a Web server to communicate with Web clients.
With CGI, you develop Web applications in any of several languages (Perl and C are two popular choices), and use the CGI interface to read data into your program. CGI is very popular since it's relatively simple. The disadvantage of CGI is that each time a client browser invokes a CGI script, the Web server must create a new process. With many computers and operating systems, creating a new process is a very expensive operation. CGI solutions can be difficult to scale to a large number of users.

Server-side scripting and Server APIs

Many Unix Web servers rely on CGI scripts. These are easily-built scripts using shell languages like C or Perl had been used with Unix for decades; CGI scripts used the same techniques. In the Windows environment, server APIs (Application Programming Interface, which tells programmers how to work with an existing application) are very popular. Internet Information Server and Apache Web Server offer APIs for integrating your own programs directly with the Web server. When you use a server API, you are actually creating a new version of the server with your program added to it. The biggest advantage of using server APIs is speed. Unlike CGI, APIs do not have to create a new process each time another user accesses your site. The downside is that your program is part of the Web server. If bugs in your program cause it to crash, it can bring the Web server down with it. Also, you need sophisticated programming skills to read and understand the server APIs, and then write code that conforms to the API. ASP is much simpler to use than server APIs . Another advantage of ASP is that it includes a component specification, which makes it easy for Web developers to build on work done by others.


ASP Server Side Scripting
ASP Server Side Scripting
Server-side scripting is a technique used in web development which involves employing scripts on a web server which produce a response customized for each user's request to the website. The alternative is for the web server itself to deliver a static web page. Scripts can be written in any of a number of server-side scripting languages that are available.
Java Servlets
Server-side scripting is distinguished from client-side scripting where embedded scripts, such as JavaScript, are run client-side in a web browser, but both techniques are often used together. Server-side scripting is often used to provide a customized interface for the user. Server-side scripting enables the website owner to hide the source code that generates the interface. With client-side scripting, the user has access to all the code existing on the client desktop or device. One drawback to the use of server-side scripting is that the client needs to make further requests over the network to the server in order to show new information to the user by means of the web browser. These requests can slow down the experience for the user, place more load on the server, and prevent use of the application when the user is disconnected from the server.

Client-side approaches are usually easier to implement and do not require access to a Web server; they become complicated when you have to support different types of browsers. Server-side solutions offer central management through Web servers' computing resources, which usually include large amounts of memory and storage. Although server-side scripting can be a little more complicated, ASP has features, presented in later lessons, to make it easier.

Example of Classic ASP Scripting

The following series of images illustrates an example of ASP scripting in an HTML page and its interpretation for the browser that has accessed the page:

1) User Browser requests an ASP Page
1) The user's browser requests an ASP Page just as it would any static HTML page.

2) Most ASP pages look like html
2) To the server, most ASP pages look like HTML pages with scripts embedded in them. In this example, the ASP portion is shown in blue. Although the user won't ever see the raw ASP page, the web server will. It processes the page from top to bottom with ASP.


3) The result of this process is an HTML page
3) The result of this process is an HTML page, which is transmitted to the browser The ASP portion has been converted to HTML (shown in blue)

4) Browser displays the resulting HTML page
4) The user's browser displays the resulting HTML code sent by the server. The browser and user aren't aware that the ASP page requested is different from the final HTML page displayed.

  1. The user's browser requests an ASP Page just as it would any static HTML page.
  2. To the server, most ASP pages look like HTML pages with scripts embedded in them.
  3. The result of this process is an HTML page, which is transmitted to the browser
  4. The user's browser displays the resulting HTML code sent by the server.

ASP Responds Browser Request
Although the user views the result of the ASP code, calculations or decisions behind the result are not evident. This characteristic is important as we discuss ASP functions and statements in a later lesson. The next lesson will examine an ASP script and its syntax.

JScript: Originally, Microsoft's clone of JavaScript, but now an implementation of the ECMAScript 262 standard for a Web scripting language and is was very similar to JavaScript.