IT581: Practicum in Web Development, Summer 2015 (Hybrid)

Dynamically generated web pages

Background


Dynamic Content


Client-side Scripting


Server-side Programming


Server-side programming capabilities

With server-side applications, you can:


Server-side languages

HTTP server software can be extended to incorporate a number of languages.

Microsoft Active Server Pages
The Microsoft IIS server supports Active Server pages (ASP). ASP files are HTML documents with special embedded script tags. The scripts written in the tags are executed by the server's ASP engine before the dpcument is returned to the client. The ASP scripts are most commonly written in VBScript or JScript (A Microsoft version of JavaScript), but other languages can be added. Similarly, JSP documents incorporate programs in the language Java that are executed by the server.
Common Gateway Interface
Web servers can also execute programs on the host computer through the Common Gateway Interface (CGI). This approach is very versatile, in that any program that can be run on the host computer can be used, but it is slower than if the processing is an integral part of the server software. CGI programs were often written in the languages C and Perl.
Server Side Includes
The Server Side Include (SSI) capability provided on most servers handles some commands directly by the server and others externally, including commands that will execute system commands and programs.
PHP
PHP is a language that was developed especially for use on the Web. The interpreter is integrated into the server, and the script code is embedded into the HTML page.
LAMP
The Apache server, the most commonly used server on the Web, supports SSI and CGI, and can be extended to handle server-executed scripting in a number of languages including the three Ps - Perl, PHP, and Python. The most common, and powerful, web server environment is referred to as "LAMP" - Linux, Apache, MySQL (a database server), and Perl/PHP/Python - all open source software products.

How many ways can we say Hello World?

Static HTML

       <html>
        <head><title>Saying Hello</title></head>
        <body>
   
         <h1>Hello World!</h1>
        </body>
       </html>

client-side JavaScript

      <html>
      
       <head>
        <title>Saying Hello</title>
          <script language="Javascript">
          <!--
          function message ()
          {
              document.write("<h1>Hello World!</h1>");
              document.close();
          }
          // -->
          </script>
      
      </head>
       <body onload="message(); return true">
       </body>
      </html>

Server Side Include

Requires that the server be appropriately configured. On wyrd.hood.edu, files must have the extension .shtml

       <html>
        <head>
         <title><!--#include file="title.txt" --></title>
        </head>
        <body>
   
         <h1><!--#include file="message.txt" --></h1>
        </body>
       </html>

where title.txt contains "Saying Hello" and message.txt contains "Hello !"

Server-side CGI script:

Requires that the server be appropriately configured. On wyrd.hood.edu, files must have the extension .cgi and must be executable. There are many language choices, including C, C++, Python, BASIC, etc. Any programming language can be used as long as it can read from standard input and write to standard output.

Unix Shell script

       #!/bin/sh
       echo -e "Content-type: text/html\n\n"
       title="Saying Hello"
       message="Hello World!"
       echo "<html>"
       echo "<head><title>$title</title></head>"
       echo "<body>"
       echo "<h1>$message</h1>"
       echo "</body>"
       echo "</html>"
       echo -e "\n"


Perl program

      #!/usr/bin/perl
      
      $title="Saying Hello";
      $message="Hello World!";
      
      print "Content-type: text/html\n\n";
      
      print "
          <html>
           <head>
            <title>$title</title>
           </head>
           <body>
            <h1>$message</h1>
           </body>
          </html>
      ";

Perl and Python applications can be made much faster by adding the mod_perl and mod_python modules to Apache. These embed the interpreters in the server, saving the step of externally running the program.

Java servlet

Requires that the server be appropriately configured

    
       import java.io.*;
       import javax.servlet.*;
       import javax.servlet.http.*;
   
       public class HelloWorldServlet extends HttpServlet {
   
         public void doGet(HttpServletRequest request,
                           HttpServletResponse response)
                           throws IOException, ServletException
         {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String title = "Saying Hello";
            String message = "Hello World!";
            out.println("<html>");
            out.println("<head><title>" + title + "</title></head>");
            out.println("<body>")
            out.println("<h1>" + message + "</h1>")
            out.println("</body>");     
            out.println("</html>");
            out.close();
         }
       }  

Comments to: dong@hood.edu
Last Modified: 21 June 2013. 18:05