Introduction to Active Server Pages Active Server Pages (ASP) ASP Architecture Basic ASP Scripting Techniques ASP Object Model Request Object Response Object
ASP Architecture
Microsoft’s solution for developing dynamic web pages ASP Architecture Microsoft’s solution for developing dynamic web pages Uses VBScript, a variant of Visual Basic A subset of VB Internet-enabled Object-oriented architecture Provides objects for various functions such as database access, file access, etc. Supported by Microsoft’s IIS and Personal Web Server
Executed by web browsers Can be VBScript, Javascript, etc. Scripting in ASP An ASP can consist of HTML code Server side script Client side script Executed by web browsers Can be VBScript, Javascript, etc. Executed by web servers May be VBScript or Javascript, etc.
Dynamically edit, change or add any content of a Web page What can ASP do for you Dynamically edit, change or add any content of a Web page Respond to user queries or data submitted from HTML forms Access any data or databases and return the results to a browser Customize a Web page to make it more useful for individual users The advantages of using ASP instead of CGI and Perl, are those of simplicity and speed Provides security since your ASP code can not be viewed from the browser Since ASP files are returned as plain HTML, they can be viewed in any browser Clever ASP programming can minimize the network traffic
<title>My First ASP Page</title> </head> A Simple ASP Example <html> <head> <title>My First ASP Page</title> </head> <body> <% Response.Write("Welcome to my first ASP generated web page.") %> <br /> <%= "Today is " & date() & " and the time is " & time() %> </body> </html>
Create a new web application in FrontPage Mapping your web folder (dt211-3studentusername) from “erin.student.comp.dit.ie” to your machine. Select start, Programs, MicroSoft FrontPage Select Open Site Type in: http://www.student.comp.dit.ie/dt211-3username Now you should be able add your ASP file now.
<title>Document title</title> A Client side example <html> <head> <title>Document title</title> <script language="vbscript"> sub vbs alert("This is VBScript") end sub </script> <script language="javascript"> function js() { alert("this is JavaScript") }
A Client side example, cont. </head> <body> Select button: <input type="button" Name="vbs" value="VBScript" onclick="vbs()" /> <input type="button" Name="js" value="Javascript" onclick="js()" /> </body> </html>
Control Flow statements are divided into 2 types. Conditional Loop Control Flow in ASP Control Flow statements are divided into 2 types. Conditional Loop Conditional statements are If…Then…Else Select…Case Looping statements are Do…Loop For…Next While…Wend
<title>ASP Loop</title> </head> <body> <% A Loop example <html> <head> <title>ASP Loop</title> </head> <body> <% Dim i for i = 1 to 6 response.write("<h" & i & ">This is header " & i & "</h" & i & ">") next %> </body> </html>
<head> <title>ASP Loop</title></head> A If example <html> <head> <title>ASP Loop</title></head> <body> <% Dim h h = hour(now()) response.write("<p>" & now()) response.write(" (Irish Time) </p>") If h < 12 then response.write("Good Morning!") else response.write("Good day!") end if %> </body> </html>
There are two types of procedures, “Sub” and “Function”. Procedures are subroutines that can be called by the main program. It contains a different script level this separating local variables from global variables. There are two types of procedures, “Sub” and “Function”. “Sub” normally doesn’t return a value while “Function” returns a value
<html><head> <title>ASP Loop</title> A procedures example <html><head> <title>ASP Loop</title> <% sub vbproc(num1,num2) response.write(num1*num2) end sub %> </head><body><p> The result of the calculation is: <%call vbproc(3,4)%> </p><p> Or, you can call a procedure like this: </p><p> The result of the calculation is: <%vbproc 3,4%> </p> </body> </html>