Overview
Lecture 11 Purpose of Server-Side Scripting Server Side Interaction Example Server-Side Technologies: • Server-Side Includes • CGI Boriana Koleva • Perl • Java Servlets and Java Server Pages Room: C54 • ASP.NET Email: [email protected] • Embedded Scripts • PHP Ajax
Examples of Server Side World Wide Web Applications
HTTP Server Client Search systems HTTP Request (inc. form data) Document management systems User registration/administration/profiles Response (HTML doc) Transactions HTML data E-commerce
Software on Server
Database
SSI – Server Side Includes Demo SSI code
Instructions to the server embedded in HTML
Server Side Includes
File extension of .shtml is usually usedThis is the main file (demoSSI.shtml) - everything between the two horizontal Server must be SSI enabled lines is held in an external file SSI instructions in HTML Comments (table.html).
SSI instructions preceded by hash ( # )
• This includes the file “myfile.html” in the main
This is the main file again
XHTML file http://scarlet.cs.nott.ac.uk/~bnk/WPS/demoSSI.shtml1 Common Gateway Interface (CGI) CGI
CGI allows browsers to request the execution of server-resident software A CGI program can produce a complete HTTP An HTTP request to run a CGI program specifies a response, or just the URL of an existing program, rather than a document document • Servers can recognize such requests in two ways: CGI programs often are stored in a directory 1. By the location of the requested file (special named cgi-bin subdirectories for such files) 2. A server can be configured to recognize executable CGI programs may be written in any language files by their file name extensions http://marian.cs.nott.ac.uk/~bnk/cgi-bin/demoCGI Most major languages have CGI libraries PERL is the most commonly used language for CGI
demoCGI code CGI
#!/bin/sh echo Content-type: text/html Some CGI programs are in machine code, but echo Perl programs are usually kept in source form, echo "" so perl must be run on them echo "
A simple CGI demo
" must be run on them first echo "The time is now:" perl date For Perl programs, if the system is echo "
" stored in /usr/local/bin/perl, (as it echo "" usually is in UNIX systems) then this is: cal #!/usr/local/bin/perl echo "" echo "" echo ""
CGI Perl
An HTML document can specify a CGI program PERL href with the hypertext reference attribute, , of • Practical Extraction and Report Language the anchor tag, , e.g.: Interpreted programming language ” Ported to most platforms Click here to run the CGI program, reply.pl Originally intended primarily for Unix
But more commonly a CGI program is called administrative tasks when the Submit button of a form is clicked Exceptionally powerful text processing