Download presentation
Presentation is loading. Please wait.
Published byJanice Pearl Washington Modified over 9 years ago
1
Server Side Programming ASP1 Server Side Programming
2
Server Side Programming ASP2 Content n Introduction n Server Side Programming (ASP) n ASP Architecture n Programming Techniques n Sample Examples
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
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. n They can't be used to refer to a database n They can lessen the burden on server n Particularly useful for 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. n Uses Server and Client Information to create and send dynamic web pages to clients
13
Active Server Pages n Is program that runs inside IIS n IIS-Internet Information Services n As free software component with windows 2000 n Option pack can be downloaded from Microsoft Server Side Programming ASP13
14
Server Side Programming ASP14 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.
15
Server Side Programming ASP15 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)
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 Client-Server Structure IIS Client request Running ASP Script... results
18
ASP Architecture n Is microsoft technology for sending client dynamic web content including XHTML,Dynamic HTML,ActiveXControls,Client Side Scripts and Java Applets n ASP Processes the request and sends response to client n When client request ASP,its loaded into memory and parsed by scripting engine named ASP.DLL Server Side Programming ASP18
19
Server Side Programming ASP19 ASP Script n ASP Script could be VBScript or Jscript 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).
20
Server Side Programming ASP20 VBScript Basics n Not case sensitive n Declaring Variables n VBScript does not require variable declarations, but it is good scripting practice to declare all variables before using them. n To declare a variable in VBScript, use the Dim, Public, or Private statement.
21
Server Side Programming ASP21 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.
22
Server Side Programming ASP22 VBScript Basics n VBScript Operators: –Arithmetic: +, -, *, /, ^ –Comparison: =, <>,, = –Logical (for Boolean variables): Not, And, Or, Xor
23
Server Side Programming ASP23 VBScript Basics n Conditional Statement: –IF … Then… Else If condition Then [Statement] elseif condition-n Then [elseifstatment]… else [elsestatements] End if
24
Server Side Programming ASP24 VBScript Basics n Loop: –Do … Loop –While …Wend –For … Next –For Each …Next n Procedures: –Sub –Function
25
Server Side Programming ASP25 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
26
ASP Demo n The response.write command is used to write output to browser n Exp <% Response.write(“Hello World”) %> Server Side Programming ASP26
27
Including Javascript <% Response.write(“Hello World”) %> Server Side Programming ASP27
28
Global.asa File n Contains Application Events n Session Events n Declarations n TypeLibrary Declarations n The #include directives n Note –Global File.asa must stored in root directory of ASP application, and each application can only contain only one Global.asa file Server Side Programming ASP28
29
Server Side Programming ASP29 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
30
Server Side Programming ASP30 Example 2 ASP Example 2 A= B= http://128.255.21.191/Example2/Example2.htm
31
Server Side Programming ASP31 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= …….
32
Server Side Programming ASP32 example 2 asp Example 2 ASP Page Example Page A+B= A-B= A*B=
33
Server Side Programming ASP33 Database Overview
34
Server Side Programming ASP34 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
35
Server Side Programming ASP35 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
36
Server Side Programming ASP36 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.
37
Server Side Programming ASP37 Example: Access n Relational database n Fairly good GUI. n Can use SQL
38
Server Side Programming ASP38 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.
39
Server Side Programming ASP39 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
40
Server Side Programming ASP40 SQL n Standard SQL commands: –Select –Insert –Update –Delete –Create
41
Server Side Programming ASP41 SQL Example database - example3.mdb tablename - table1 columnname - ID, ItemName, Price
42
Server Side Programming ASP42 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
43
Server Side Programming ASP43 SQL Basic n Insert tablename (fieldname1, fieldname2…) values (value1, value2) n update tablename set column_name1=expression1
44
Server Side Programming ASP44 SQL Basic n Create tablename (fieldname1 type, fieldname2 type) n Delete [*] from tablename where clause (deletes whole row)
45
Server Side Programming ASP45 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
46
Server Side Programming ASP46 Operation database Server Client HTML ASP
47
Server Side Programming ASP47 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
48
Server Side Programming ASP48 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)
49
Server Side Programming ASP49 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
50
Server Side Programming ASP50
51
Server Side Programming ASP51 HTML Forms Example http://128.255.21.191/Example3/Example3.htm
52
Server Side Programming ASP52 Step II: Database n Under the home directory, create the access database named “Candy.mdb” n tablename - Products n columnname - ID, ItemName, Price
53
Server Side Programming ASP53 <% 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 %>
54
Server Side Programming ASP54 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)
55
Server Side Programming ASP55 Result
56
Server Side Programming ASP56 Java2 Enterprise Edition EJBs (Enterprise JavaBeans) ----picture PCWeek
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.