Title: Introduction to Active Server Pages
1Introduction to Active Server Pages
- Introduction to
- Active Server Pages (ASP)
- ASP Architecture
- Basic ASP Scripting Techniques
- ASP Object Model
- Request Object
- Response Object
2ASP Architecture
3ASP Architecture
- Microsofts 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 Microsofts IIS and Personal Web
Server
4Scripting in ASP
- An ASP can consist of
- HTML code
- Server side script
- Client side script
- Client side script
- Executed by web browsers
- Can be VBScript, Javascript, etc.
- Server side script
- Executed by web servers
- May be VBScript or Javascript, etc.
5What 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
6A Simple ASP Example
lthtmlgt ltheadgt lttitlegtMy First ASP
Pagelt/titlegt lt/headgt ltbodygt lt
Response.Write("Welcome to my first ASP generated
web page.") gt ltbr /gt lt "Today is " date()
" and the time is " time() gt lt/bodygt lt/htmlgt
7Create 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-3use
rname - Now you should be able add your ASP file now.
8A Client side example
lthtmlgt ltheadgt lttitlegtDocument titlelt/titlegt
ltscript language"vbscript"gt sub vbs
alert("This is VBScript") end sub
lt/scriptgt ltscript language"javascript"gt
function js() alert("this is
JavaScript") lt/scriptgt
9A Client side example, cont.
lt/headgt ltbodygt Select button ltinput
type"button" Name"vbs" value"VBScript"
onclick"vbs()" /gt ltinput type"button" Name"js"
value"Javascript" onclick"js()"
/gt lt/bodygt lt/htmlgt
10Control Flow in ASP
- Control Flow statements are divided into 2 types.
- Conditional
- Loop
- Conditional statements are
- IfThenElse
- SelectCase
- Looping statements are
- DoLoop
- ForNext
- WhileWend
11A Loop example
lthtmlgt ltheadgt lttitlegtASP Looplt/titlegt lt/headgt ltbo
dygt lt Dim i for i 1 to 6
response.write("lth" i "gtThis is header " i
"lt/h" i "gt") next gt lt/bodygt lt/htmlgt
12A If example
lthtmlgt ltheadgt lttitlegtASP Looplt/titlegtlt/headgt ltbody
gt lt Dim h h hour(now()) response.write("ltpgt"
now()) response.write(" (Irish Time) lt/pgt") If h
lt 12 then response.write("Good
Morning!") else response.write("Good
day!") end if gt lt/bodygt lt/htmlgt
13Procedures
- 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 doesnt return a value while
Function returns a value
14A procedures example
lthtmlgtltheadgt lttitlegtASP Looplt/titlegt ltsub
vbproc(num1,num2)response.write(num1num2)end
subgtlt/headgtltbodygtltpgtThe result of the
calculation is ltcall vbproc(3,4)gtlt/pgtltpgtOr,
you can call a procedure like thislt/pgtltpgtThe
result of the calculation is ltvbproc
3,4gtlt/pgtlt/bodygtlt/htmlgt