UNIT 3:
Server – Side Scripting:
Chapter 8: Server-Side Scripting
Chapter 9: Programming Languages for
Server-Side Scripting
Chapter 8: Server – Side Scripting
8.1 Introduction to the Server Side Scripting
“SERVER-SIDE SCRIPTING IS A WEB SERVER TECHNOLOGY IN WHICH A
USER'S REQUEST IS FULFILLED BY RUNNING A SCRIPT DIRECTLY ON
THE WEB SERVER TO GENERATE DYNAMIC HTML PAGES.”
Server Side Scripting
It is usually used to provide interactive web sites that interface to databases or
other data stores. This is different from client-side scripting where scripts are
run by the viewing web browser, usually in JavaScript. The primary advantage
to server-side scripting is the ability to highly customize the response based on
the user's requirements, access rights, or queries into data stores.
When the server serves data in a commonly used manner, for example
according to the HTTP or FTP protocols, users may have their choice of a
number of client programs. In the case of more specialized applications,
programmers may write their own server, client, and communications protocol,
that can only be used with one another.
Programs that run on a user's local computer without ever sending or receiving
data over a network are not considered clients, and so the operations of such
programs would not be considered client-side operations.
Some of the technologies designed mainly or exclusively for server-side
scripting, typically by embedding instructions directly in template web pages
are as follows:
CGI (common Gateway Interface)
ASP (Active Server Pages)
JSP (Java Server Pages)
8.1.1 Common Gateway Interface
“THE COMMON GATEWAY INTERFACE, OR CGI, IS A STANDARD FOR
EXTERNAL GATEWAY PROGRAMS TO INTERFACE WITH INFORMATION
SERVERS SUCH AS HTTP SERVERS.”
The Common Gateway Interface (CGI) is a set of rules that specifies how
parameters are passed from programs to Web servers. When a user submits a
form, a program may be executed by the Web server, and the results are
returned to the browser. The particular program that is to be executed is
specified in the ACTION attribute of the form tag. In general, any program run
by a Web server in response to a user’s request is called a script or CGI script.
Server Side Scripting
8.1.2 Active Server Pages (ASP)
“ACTIVE SERVER PAGES OR ASP IS A TECHNOLOGY THAT ENABLES THE
DESIGNERS TO MAKE DYNAMIC AND INTERACTIVE WEB PAGES.”
ASP uses server side scripting to dynamically produce web pages that are not
affected by the type of browser the web site visitor is using.
The default scripting language used for writing ASP is VBScript, although the
designer can use other scripting languages like Jscript (Microsoft’s version of
JavaScript).
ASP pages have the extension .asp instead of .htm, when a page with the
extension .asp is requested by a browser the web server knows to interpret any
ASP contained within the web page before sending the HTML produced to the
browser. This way all the ASP is run on the web server and no ASP will ever be
passed to the web browser.
Any web pages containing ASP cannot be run by just simply opening the page
in a web browser. The page must be requested through a web server that
supports ASP, this is why ASP stands for Active Server Pages, no server, no
active pages.
8.1.3 Java Server Pages (JSP)
“JAVA SERVER PAGES (JSP) IS A TECHNOLOGY THAT LETS THE
DESIGNER MIX REGULAR, STATIC HTML WITH DYNAMICALLY –
GENERATED HTML.”
Many web pages that are built by CGI programs are mostly static, with the
dynamic part limited to a few small locations. But most CGI variations,
including servlets, make the designer generate the entire page via their
program, even though most of it is always the same. JSP lets the designer
create the two parts separately.
Server Side Scripting
8.1.3.1 Features of JSP
JSP gives an ideal platform for creating web applications easily and quickly. The
various features supported by JSP are:
1. Platform and Server Independence. The JSP technology follows
the ‘write once’ run anywhere, rule which is the basis of the java
language. JSP technology can run on various web server including
Apache, Netscape and IIS and is supported by a large variety of tools
from different vendors.
2. Environment. JSP uses pure java and takes full advantage of its
object-oriented nature. This technology lets the designer separate
content generation from layout by accessing component from the page.
3. Extensible JSP Tags. JSP uses a combination of tags and scripting
to create dynamic web pages. It allows the designer to extend the JSP
tags available. JSP developers can create custom tag libraries, so that
more functionality can be extracted using XML-like tags and this leads to
less use of scripting in JSP pages.
4. Reusability Across Platform. The JSP pages uses components
which are reusable. These reusable components help keep the pages
simple and run faster.
5. Easier Maintenance. Application made using JSP technology are
easier to maintain.
8.2 Common Gateway Interface
“THE COMMON GATEWAY INTERFACE, OR CGI, IS A STANDARD FOR
EXTERNAL GATEWAY PROGRAMS TO INTERFACE WITH INFORMATION
SERVERS SUCH AS HTTP SERVERS.”
The Common Gateway Interface (CGI) is a set of rules that specifies how
parameters are passed from programs to Web servers. When a user submits a
form, a program may be executed by the Web server, and the results are
returned to the browser. The particular program that is to be executed is
specified in the ACTION attribute of the form tag. In general, any program run
by a Web server in response to a user’s request is called a script or CGI script.
Server Side Scripting
A plain HTML document is static i.e. constant whereas a CGI program is
dynamic i.e. executed on real time.
A CGI program is executed by the web daemon to transmit the information to
the database engine and return the result to the client. Thus it is called as a
gateway.
It can be written in any language like C/C++, FORTRAN, Visual Basic, etc.
8.2.1 Get the form data from
There are two methods which can be used to access the forms. These are GET
and POST:
GET (in the FORM tag):
The CGI program will receive the encoded form input in the environment
variable QUERY_STRING.
POST (in the FORM tag):
CGI program will receive the encoded form input on stdin. The server will NOT
send an EOF on the end of the data, instead the user should use the
environment variable CONTENT_LENGTH to determine how much data to be
read from stdin.
8.2.2 A simple CGI Script
A simple CGI script (A Perl program) that just prints an HTML document. It’s all
same as using HTML tags as simple. The only main part is the first line must
be:
Content – type: text/html
So that the browser knows what kind of document it is and therefore how to
display it. To send plain ASCII documents one can use text/plain. For
Server Side Scripting
multimedia documents like sound and images the content should be specified
appropriately.
The second line (important) must be blank (a line feed), reserved for future
development.
8.2.3 Forms
Usually the information supplied by the QUERY_STRING variable should come
from the user pressing buttons and entering text in HTML document. This
information to be packaged and sent to the CGI script. Each group of buttons
and text boxes is called a form. The user also has to tell it the URL to send the
information to, and how the information is sent. The result is something like
this:
<form action=http://www/comp.leeds.ac.uk/sam-cgi/answerme”
method=”GET”>
Some text in here.
It can be anything except another form.
</form>
The action attribute of the tag gives the URL of the CGI script.
8.2.4 Submit Buttons, Checkboxes, Radiobuttons
A submit button is the input device that actually calls the URL. It has a value
which is the message that appears on the button. For example:
<form action = ” http://www/comp.leeds.ac.uk/cgi-bin/Perl/example”
method=”GET”>
<input type = ”submit” value = “Click me”></form>
Server Side Scripting