Presentation is loading. Please wait.

Presentation is loading. Please wait.

Server Side Programming ASP1 Server Side Programming Database Integration Peter O’Grady.

Similar presentations


Presentation on theme: "Server Side Programming ASP1 Server Side Programming Database Integration Peter O’Grady."— Presentation transcript:

1 Server Side Programming ASP1 Server Side Programming Database Integration Peter O’Grady

2 Server Side Programming ASP2 Content n Introduction n Server Side Programming (ASP) n Database n Integration

3 Server Side Programming ASP3 Introduction n Internet allows for client-server systems n Programs can be invoked on either/both clients and servers: –Client side includes Java Applets, ActiveX components with JScript or VBScript. –Server side includes CGI and ASP n Data can be kept on servers distributed across network and accessed via client (topic of this portion of course)

4 Server Side Programming ASP4 Why use Internet to access data? n People can access the data using a familiar browser interface. No special software required. n Data can be maintained centrally or distributed. n Data can be integrated with other information in an institution’s web pages n Information can be made available to anyone (with permission) on the Internet

5 Server Side Programming ASP5 How can database be accessed by web browser? Web browser Server Side Programming e.g. Microsoft IIS server : ASP (VBScript, JScript, SQL) Internet Database

6 Server Side Programming ASP6 Client Side Scripts n They are browser-specific, so the same code may be interpreted differently depending on the browser being used. (Note recent use of ECMAScript as general JScript or JavaScript) n They can't be used to refer to a database (such as a product catalog). n They can lessen the burden on server and are particularly useful for such tasks as validating data before sending to server side to be processed.

7 Server Side Programming ASP7 Server Side Programming (ASP)

8 Server Side Programming ASP8 Content n Server Side programming overview n Example –Microsoft Internet Information Services (IIS) –Active Server Page(ASP) –VBScript/JScript

9 Server Side Programming ASP9 Common Gateway Interface (CGI) n CGI Is a standard for interfacing external applications with web servers (Common Gateway Interface, 1995). n Involves a new process each time it is invoked therefore can be slow with multiple users. n Alternatives: ISAPI (ASP), NSAPI.

10 Server Side Programming ASP10 IIS n IIS is a web server that runs on Win NT, 2000, Server2003 and XP Server. n Can use component-based (COM/ActiveX) client/server applications as well as JScript (ECMAScript) and VBScript

11 Server Side Programming ASP11 What is ASP? "a server - side scripting environment that you can use to create and run dynamic, interactive, high - performance Web server applications”. Microsoft Can include COM/ActiveX components and/or compiled code Runs on IIS

12 Server Side Programming ASP12 What are Active Server Pages? n Server-side environment n Can provide compile-free application environment n Combine HTML, scripts, COM and ActiveX server components.

13 Server Side Programming ASP13 Using ASP n User usually completes HTML form in a browser and submits this to a.asp file on the server (note that you need a.asp file on the server) n.asp file contains both HTML and scripts/components n Scripts/components invoked and produce new HTML code n resulting page: original HTML + new HTML (generated by asp) - this is sent to client.

14 Server Side Programming ASP14 Using ASP n Server evaluates tag starting with n Scripts/components contained within tags n Web servers supporting ASP: –Personal Web Server (Windows 95, 98, NT) –Internet Information Services (Windows NT Server, 2000 Server, Server 2003, XP)

15 Server Side Programming ASP15 ASP Application n Dell Computers –http://www.dell.comhttp://www.dell.com n Barnes and Noble Book Store –http://www.bn.comhttp://www.bn.com n Pricescan –http://www.pricescan.comhttp://www.pricescan.com

16 Server Side Programming ASP16 ASP Basics n ASP file is a text file with the extension.asp n it contains any combination of: –Text –HTML Tags –ASP Script Commands/Components

17 Server Side Programming ASP17 ASP Script n ASP Script could be VBScript or Jscript (ECMAScript) n A script is a series of commands or instructions. n Script command instructs the web server to perform an action. n VBScript is similar to Visual Basic and Visual Basic for Application (VBA).

18 Server Side Programming ASP18 VBScript Basics n Not case sensitive n Declaring Variables VBScript does not require variable declarations, but it is good scripting practice to declare all variables before using them. To declare a variable in VBScript, use the Dim, Public, or Private statement.

19 Server Side Programming ASP19 Declaring Variables Dim: Declares variables and allocates storage space. Variables declared with Dim at the script level are available to all procedures within the script. At the procedure level, variables are available only within the procedure. Ex. Dim A,B Private: Used at script level to declare private variables and allocate storage space. Private variables are available only to the script in which they are declared Public: Used at script level to declare public variables and allocate storage space. Variables declared using the Public statement are available to all procedures in all scripts in all projects.

20 Server Side Programming ASP20 VBScript Basics n VBScript Operators: –Arithmetic: +, -, *, /, ^ –Comparison: =, <>,, = –Logical (for Boolean variables): Not, And, Or, Xor

21 Server Side Programming ASP21 VBScript Basics n Conditional Statement: –IF … Then… Else If condition Then [Statement] elseif condition-n Then [elseifstatment]… else [elsestatements] End if

22 Server Side Programming ASP22 VBScript Basics n Loop: –Do … Loop –While …Wend –For … Next –For Each …Next n Procedures: –Sub –Function

23 Server Side Programming ASP23 ASP Demo n ASP uses to enclose script commands. ASP Example 1 This page was last refreshed on Now it is Note 1: The VBScript function Now returns the current time, Date returns current date. Note 2: No data is input by the user

24 Server Side Programming ASP24 Running ASP n Save file with.asp extension on server n Client accesses the file in similar fashion to.htm (or.html) file n Server detects.asp extension and runs script within ASP tags n Results sent to client http://128.255.21.191/Example1/Example1.asp

25 Server Side Programming ASP25 Client-Server Structure IIS Client request Running ASP Script... results

26 Server Side Programming ASP26 Example 2 ASP Example 2 A= B= http://128.255.21.191/Example2/Example2.htm

27 Server Side Programming ASP27 Example 2 see web site Contained in HTML code: <% dim A, B A=Request.form("ValueofA") B=Request.form("ValueofB") %> ………. A+B= A-B= A*B= …….

28 Server Side Programming ASP28 example 2 asp Example 2 ASP Page Example Page A+B= A-B= A*B=

29 Server Side Programming ASP29 Database Overview

30 Server Side Programming ASP30 What is a Database? n A database is an organized collection of related data, typically stored on disk, and accessible by possibly many concurrent users. n Most common is relational database, which is a tabular database in which the data is defined so that it can reorganized and accessed in a number of different ways

31 Server Side Programming ASP31 Database Management Systems n DBMS n A program to access, manipulate and present the data to a user. n Example DBMS: –Oracle –Sybase (Microsoft SQL) –IBM’s DB2, IMS and SQL/DS –dBase –Access

32 Server Side Programming ASP32 Relational Database Structure n set of tables containing data fitted into predefined categories. n each table(relation) contains one or more data categories in columns. n each row contains a unique instance of data for the categories defined by column.

33 Server Side Programming ASP33 Example: Access n Relational database n Fairly good GUI. n Can use SQL

34 Server Side Programming ASP34 Relationships in Access n Multiple tables in one database n Matching key fields between table –A key is usually a field with the same name in both tables. –Such key is primary key for one table, foreign key in the other table.

35 Server Side Programming ASP35 SQL n SQL: Structured Query Language n It is used to query from and update database. n Systems using SQL: Oracle Sybase Microsoft SQL server Access

36 Server Side Programming ASP36 SQL n Standard SQL commands: –Select –Insert –Update –Delete –Create

37 Server Side Programming ASP37 SQL Example database - example3.mdb tablename - table1 columnname - ID, ItemName, Price

38 Server Side Programming ASP38 SQL Example n To find out the ‘Price’ when ‘ItemName’ equals to Candy SELECT Price FROM Table1 WHERE ItemName = ‘Candy’ Note: Can SELECT * to return whole row as an object - see Example 3 on website

39 Server Side Programming ASP39 SQL Basic n Insert tablename (fieldname1, fieldname2…) values (value1, value2) n update tablename set column_name1=expression1

40 Server Side Programming ASP40 SQL Basic n Create tablename (fieldname1 type, fieldname2 type) n Delete [*] from tablename where clause (deletes whole row)

41 Server Side Programming ASP41 Database Integration Requirements n Server (IIS) n Database Internet database connector (ODBC) not always required can use ADODB n Dynamic Web Page (asp) User Input using HTML forms Data Transmission Retrieving data from database Display results

42 Server Side Programming ASP42 Operation database Server Client HTML ASP

43 Server Side Programming ASP43 Using web browser to access a database n Web pages and forms are used to provide access to the database. n Database can be queried or updated. n Platform-independent front-end. n Database vendor-independent front-end n Client machine does not need database networking software

44 Server Side Programming ASP44 Example Implementation n Step 1: HTML file (containing forms) for user input on server. n Step 2: Database on server n Step 3: Setup database connection (ODBC)

45 Server Side Programming ASP45 Step I: HTML File with Forms n Example: Gum Suckers Taffy Skittles M&Ms Lifesavers Snickers This captures user input and sends result to result.asp

46 Server Side Programming ASP46

47 Server Side Programming ASP47 HTML Forms Example http://128.255.21.191/Example3/Example3.htm

48 Server Side Programming ASP48 Step II: Database n Under the home directory, create the access database named “Candy.mdb” n tablename - Products n columnname - ID, ItemName, Price

49 Server Side Programming ASP49 <% dim price Set MyConn = Server.CreateObject("ADODB.Connection") set rs = Server.CreateObject("ADODB.Recordset") MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath ("Candy.mdb") item = Request.form("item") Set RS = MyConn.execute("Select * from Products where Candy = '" & item & "'") if rs.Eof then Price = "" else Price = RS("Price") End if Response.Write("It will cost you $" & price) Set MyConn = nothing Set rs = nothing %>

50 Server Side Programming ASP50 Running ASP n Check the extension (asp) n server evaluates tag starting with n server replaces the tags with normal HTML using scripts n results page: original Markup + new Markup(generated by asp)

51 Server Side Programming ASP51 Result

52 Server Side Programming ASP52 Java2 Enterprise Edition EJBs (Enterprise JavaBeans) ----picture PCWeek


Download ppt "Server Side Programming ASP1 Server Side Programming Database Integration Peter O’Grady."

Similar presentations


Ads by Google