ServerSide Web Programming with Active Server Pages Introduction

Server-Side Web Programming with Active Server Pages Introduction 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 1

Dynamic Web Content • Web originally consisted of static content. • Increasingly sophisticated uses of web rely on dynamically generated content. • Dynamic content is not fixed - site content or functionality changes because of: – – – User input (forms) Database content Personalization Where user came from Other factors • Sounds easy? Not! 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 2

Dynamic Web Content • Dynamic web content can be implemented on the client or the server. • Client-side Dynamic Content – Often faster (lower bandwidth) and requires less of expensive network resources. – Diverse implementations of client-side dynamic content technologies are problematic. • Server-Side Dynamic content – Can be programmed to be browser-neutral. – Requires more server resources than static content. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 3

Server-Side Dynamic Web Content • Programming server-side dynamic content for the web is complex because: – The web is a client/server environment— implementation “issues” are distributed… – The web is based on the HTTP protocol, which does not maintain user state between actions. (more later) • Deeply understanding and applying these concepts is where the “big money” is… 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 4

Client/Server Architecture • Client/Server computing involves “clients” requesting and receiving services (e. g. , files, printing, web) from “servers”. • The web is intrinsically client/server—a user’s browser requests/receives a web page from a webserver. • Although a “client” is typically a user’s PC or workstation, a server can also be a “client” of another server (e. g. , webserver requesting data from a database server). 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 5

Client/Server: Clients In addition to web browsers, there are many different types of clients: – – – 11/6/2020 FTP software Video/Audio player browser add-ons Internet Telephony Applications News service feeds Custom applications that connect to databases over the Internet. © 2000, Valtara Digital Design/Blitzkrieg Software 6

Client/Server: Servers • Servers are normally permanent, fixed resources. If they are on the Internet, they have the same fixed IP address. • Servers run operating systems such as Windows NT or Linux that are multitasking and can run unattended for long periods. • Server hardware is different from PCs or Macs. Server hardware is designed to support multiple users and to be on all the time. • Many sites use redundant server hardware so that the services they provide are available all of the time. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 7

Client/Server Architecture • Programs/applications can be architected for client/server environment. • Client/server applications are a logical extension of modular programming--separation of a large piece of software into parts ("modules") can simplify development via reuse and centralized maintenance. • Client/server applications can be classified by how they are distributed--these are called layers. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 8

Client/Server Layers • Applications can be conceptually distributed into 3 layers: – Presentation layer • Handles the user interface (UI) – Business logic layer • Handles business rules/logic, e. g. , debit an account when making a withdraw from the ATM. – Storage layer • Where the information is persistently stored. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 9

Layers and Tiers • Layers are an abstract, generalized model. Tiers are the actual physical implementation of a client/server application. • Storage layer is critical for professional applications. Transactions on the storage layer must support ACID: – ATOMICITY: Transaction should be done or undone completely. In the event of failure, data should rollback to previous state. – CONSISTENCY: Transaction should transform a system from one consistent state to another consistent state. – ISOLATION: each transaction should happen independently of other transactions occurring at the same time. – DURABILITY: Completed transactions should remain permanent, even during system failure. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 10

Client/Server Application Tiers • One Tier – All the layers are on one computer (e. g. , a Fox. Pro or MS Access application). • Two tier – The user interface and business logic reside on the workstation and the data on the network (e. g. , a VB application against a SQL*Server database). • N-Tier – Each layer resides on different machines. In some cases, multiple servers can involved (e. g. , ASP web page on webserver queries database and GIS servers. ). 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 11

Client/Server Tiers 1 tier User Interface Business Logic Storage 11/6/2020 2 tier All on one Client machine N-Tier Client Web MTS Server File Server © 2000, Valtara Digital Design/Blitzkrieg Software SQL Server 12

Server-side Dynamic • Currently most Internet-based dynamic web content is implemented with server-side computing. • Most common implementation of server-side computing is via scripting interfaces/plug-ins rather than writing directly to the CGI model. • PERL, ASP, and Java are some of the more popular web server-side scripting interfaces. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 13

Server-side Dynamic Content Models • CGI model – Code with HTML (also Fox. Web). – Programs generate HTML when passed request information. • ASP/Fusion – HTML with embedded code. – Microsoft’s ASP solution will be focus of several lectures. • Server-side work objects – Java. Beans, MTX objects, 3 rd party server-side tools like discussion engines, etc. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 14

What is CGI? • “Common Gateway Interface” • A protocol that allows an application to: – Receives from the webserver the contents of a user request (including URL, request variables, and user parameters) – Return a data stream to the webserver (HTML) • Typical request: http: //myserver/cgi-bin/my. Script? Arg 1=X&Arg 2=Y • CGI argument format is the basis for ASP. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 15

CGI • Most CGI implementations require the CGI logic to be loaded, a process spawned, and after completion, the process killed for each request, reducing scalability. • CGI most commonly implemented using pre-built applications that implement server-side scripting (PERL is one of the most popular scripting languages). 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 16

CGI and How It Works For forms whose action property is 'GET' the form elements are sent as parameters after the ? Separated by & For forms whose action property is 'POST' the form elements are sent as part of the message content to the server. <form method='___' action='http: //my. Server/cgi-bin/my. Script'> (Script can also be a binary program on the server) 1 </form> Page on Client 3 my. Server STDOUT: Returned as HTML to Caller /cgi-bin/my. Script 2 Submit CGI Scripts receive POST data as STDIN: Link 1 2 http: //my. Server/cgi-bin/my. Script? Arg 1=X&Arg 2=Y 11/6/2020 Arguments (after the ? , passed as arguments to script) © 2000, Valtara Digital Design/Blitzkrieg Software 17

ISAPI • “Internet Server Application Programming Interface” • Microsoft technology to expand improve CGI. • Similar to CGI in that is normally accessed via a scripting interface/plug-in. • ISAPI logic loaded once on first demand shares the webserver's process. • Similar technologies created by other vendors. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 18

Drawbacks of CGI and ISAPI • Writing applications that directly use CGI or ISAPI have large overhead, especially for the implementing the interface code. • Pre-built scripting applications like PERL requires user to script all HTML elements -- harder to read and maintain. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 19

Scripting Languages • Many scripting languages available: – PERL (From Unix) – Java (From Sun Microsystems) – Java. Script (As used in DHTML) – VBScript (From Microsoft) – Others (Lots) 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 20

ASP Basics • ASP = Active Server Pages (acronym in trade literature sometimes refers to Application Server Provider) • A web technology for combining scripting code (that runs on the server as the page is loaded by the web server) with HTML and other web page content. • Files with the. asp or. asa extension are passed to an ISAPI-based IIS plug-in (asp. dll) • Asp. dll interprets the file, executes any ASP script it contains, and outputs it as HTML. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 21

ASP Basics • ASP code indicated in one of two ways – Embedded withing <% %> marks – Uses HTML <SCRIPT> element <script language=vbscript runat=server></script> • ASP server-side script stripped off and not passed to client. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 22

ASP Sample - #1 <html> <head> <title>ASP Example 1</title> </head> <body> <script Language="vbscript" runat="server"> Response. Write("The date is " & date ) </script> </body> </html> 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 23

ASP Sample - #2 <html> <head> <title>ASP Example 2</title> </head> <body> The date is <%= date() %> </body> </html> 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 24

ASP Object Model • ASP is not a programming language. It is an object model that scripting languages can manipulate. • ASP object model provides many services that abstract the complexities of server programming: – User input – Browser output – Session management – Component creation and management 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 25

ASP in Action Client Response Server Object Request Application Object. Context Session Object From Prof. Server Pages (WROX) p. 83 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 26

ASP is Language Neutral • ASP can be programmed using many languages. • Microsoft's VBScript and JScript ship with IIS. • ASP assumes VBScript unless otherwise indicated. Best practice is to always specify. – Set a page default <%@ LANGUAGE=VBSCRIPT%> – Change default on a per-script basis <script language=jscript runat=server> – Change default on webserver via registry 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 27

Using ASP • ASP can be very simple and implemented as a: – Small, single-page application. – Web application--a collection of many related ASP pages that provide a specific service or function. – Host of custom, server-side compiled objects. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 28

ASP Benefits • Relatively simple programming model. • Can script in many different languages. • Server-side functionality allows creation of "browser neutral" web pages. • Mixed HTML/Script works well for web-oriented developers. • Ported to many non-Microsoft platforms. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 29

ASP Benefits (continued) • No design-time compiling - Fixes/enhancements available immediately. • VBScript language leverages VB skills. • Scales very well to moderate-sized sites. • Used by many developers--many help resources. • Free with NT Server. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 30

ASP Drawbacks • Primarily a "Microsoft" technology. However, they have licensed the technology widely. • Simplicity can lead to poor design and scalability. • Mixed HTML/script model confusing to some programmers. • Page designers altering the HTML who are nonprogrammers can “muddle” the code. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 31

ASP Web Applications Challenges • Managing database connections - connection pooling. • Maintaining user state information. • Minimizing server resources to maximize scalability. • Building apps that will last. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 32

ASP Intrinsic Objects • • • Request - Exposes what client sent to server. Response - Collects output back to client. Application - Represents the ASP page itself. Session - represents a continuity of connection. Server - provides services to the application. Object. Context - For MTX and transactions. 11/6/2020 © 2000, Valtara Digital Design/Blitzkrieg Software 33
- Slides: 33