Server-side Scripts & Database Connectivity
 CIS311 Dr. Drew Hwang

Client-Server Interaction

  1. Getting the data from the client to the server.
  2. Processing the data on the server.
  3. Sending the results from the server to the client.

Form-Script Interaction

  1. Picks the name of the script from the ACTION attribute.
  2. Collects all the data from the various controls on the form and places them next to each other with the symbol & between them.
  3. Generates the entire string that uses the format: cgiURL?data, where the data is a string that holds all the data entered by the user.

Server Applications Development

Internet Server Application Program Interface (ISAPI)

[08_i260b  3328 bytes ]

  • One example of the ISAPI application is Microsoft's Internet Database Connector. ISAPI extensions can also be combined with the Internet Database Connector (IDC) to create highly interactive sites. In this, Web browsers submit requests to the Internet server by using HTTP. The Internet server responds with a document formatted in HTML. Access to databases is accomplished through a component of Internet Information Server called the IDC. The Internet Database Connector, Httpodbc.dll, is an ISAPI DLL that uses ODBC to gain access to databases.
  • The IDC uses two types of files to control how the database is accessed and how the output Web page is constructed. These files are Internet Database Connector (.idc) files and HTML extension (.htx) files. The .idc file can be placed into the <Form> tag (e.g., <FORM METHOD="POST" ACTION="/scripts/samples/sample2.idc">)or the <A> tag (e.g., <A HREF="http://webserver/samples/dbsamp/dbsamp1.idc">Click here to run query</A>). A sample .idc file and a sample .htx file look like this:
  • .idc .htx (only the portion that displays the results in table)
    Datasource: Web SQL
    Username: sa
    Template: sample.htx
    SQLStatement:
    + SELECT au_lname, ytd_sales
    + from pubs.dbo.titleview
    + where ytd_sales>5000
    <TABLE BORDER>
    <%begindetail%>
    <%if CurrentRecord EQ 0 %>
    <caption>Query results:</caption>
    <TR>
    <TH><B>Author</B></TH>
    <TH><B>YTD Sales<BR>(in dollars)</B></TH>
    </TR>
    <%endif%>
    <TR>
    <TD>
    <A HREF="/scripts/samples/sample3a.idc?lname=
    <%au_lname%>"><%au_lname%></A>
    </TD>
    <TD align="right">$<%ytd_sales%></TD>
    </TR>
    <%enddetail%>
    </TABLE>

    [08_i260n  4533 bytes ]

    Common Gateway Interface (CGI)

    [08_i260e  3494 bytes ]

    Server Scripts Development

    Client-side vs. Server-side Scripting

    Client-
    Side
    Adv.
    • Client-side scripts share the processing burden of the Web server and relax the bandwidth demand on the Internet.
    • Client-side functionality is extended through using ActiveX controls.
    • Client-side scripting creates interactive (or dynamic) Web pages.
    • Client-side scripting creates interactive (or dynamic) dynamic forms.
    • Client-side scripting adds flexibility in creating user interface.
    • Client-side scripts provide instant feedback to users.
    Disadv.
    • Client-side scripting is browser (brand and version)-dependent.
    • Client-side scripting is computer platform dependent.
    • Source code of client-side scripts is not secured.
    • The client-side scripts make the pages bulky.
    • Variable scope is limited to a single page.
    • It takes longer to download pages with ActiveX controls.
    • Client-side scripting has limited error handling and debugging support.
    • Client-side scripting provides no direct access to system objects.
    Server-
    side
    Adv.
    • Server-side scripts are browser-independent.
    • Global variables are available with server-side scripting.
    • Web pages can be dynamically customized based on user input (e.g., browser identity, screen resolution, etc.)
    • Server-side scripts are secured.
    • Server-side scripts provide live data through interfacing with server database.
    • ActiveX controls can be used on the server without being sent to the client.
    • HTTP server variables are available for server-side scripts for more functionalities.
    Disadv.
    • No debugging tools available for server-side scripting
    • No direct control over the user interface for server-side scripting.
    • Server-side scripting is more difficult.
    • It's hard to know when a session ends (i.e., the session variable cannot be cleared).

    * Mike Morrison, et. al., "Using Microsoft Visual InterDev," QUE, 1997.

    Sample HTTP Server Variables

    Variable Sample Value
    AUTH_TYPE  
    CONTENT_LENGTH 0
    CONTENT_TYPE  
    GATEWAY_INTERFACE CGI/1.1
    LOGON_USER  
    PATH_INFO /ASPSamp/Samples/srvvar.asp
    PATH_TRANSLATED C:\inetpub\ASPSamp\Samples\srvvar.asp
    QUERY_STRING  
    REMOTE_ADDR 134.71.244.49
    REMOTE_HOST 134.71.244.49
    REQUEST_METHOD GET
    SCRIPT_MAP  
    SCRIPT_NAME /ASPSamp/Samples/srvvar.asp
    SERVER_NAME dhsystem
    SERVER_PORT 80
    SERVER_PORT_SECURE 0
    SERVER_PROTOCOL HTTP/1.0
    SERVER_SOFTWARE Microsoft-IIS/3.0
    URL /ASPSamp/Samples/srvvar.asp
    HTTP_ACCEPT image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*
    HTTP_ACCEPT_LANGUAGE en
    HTTP_CONNECTION Keep-Alive
    HTTP_HOST dhsystem
    HTTP_REFERER http://dhsystem/ASPSamp/Samples/Samples.htm
    HTTP_UA_PIXELS 640x480
    HTTP_UA_COLOR color8
    HTTP_UA_OS Windows NT
    HTTP_UA_CPU x86
    HTTP_USER_AGENT Mozilla/2.0 (compatible; MSIE 3.02; Windows NT)
    HTTP_COOKIE ASPSESSIONID=ZFHSRTKJPWCAHYRE