Introduction to Active Server Pages ASP - PowerPoint PPT Presentation

Loading...

PPT – Introduction to Active Server Pages ASP PowerPoint presentation | free to view - id: 5cba7-NmRmN



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Introduction to Active Server Pages ASP

Description:

Introduction to Active Server Pages (ASP) Marios Tziakouris. University of Cyprus. EPL602 ... Active Server Pages (ASP). Now version 3.0 ... – PowerPoint PPT presentation

Number of Views:9119
Avg rating:3.0/5.0
Slides: 60
Provided by: JeffreyA159
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Introduction to Active Server Pages ASP


1
Introduction to Active Server Pages (ASP)
  • Marios Tziakouris
  • University of Cyprus
  • EPL602
  • Fall 2004

2
Objectives
  • What is ASP?
  • Compare and contrast ASP with standard HTML
  • Compare ASP to client-side and server-side
    scripting languages
  • ASP Crash Course
  • ASP Objects

3
Objectives (continued)
  • Connecting to databases
  • Tools you need to create ASP applications
  • Steps to start developing
  • Reference tools
  • Myths of ASP
  • Conclusions and Q A

4
What is ASP?
  • Active Server Pages (ASP). Now version 3.0
  • Microsoft Technology running on Internet
    Information Services (IIS)
  • Its not a language neither an application
    primarily it is a technology
  • A series of objects and components that are
    executed on the web server
  • Uses a suite of technologies that allows
    dynamically-generated content
  • Control of how content is generated from the
    server to the browsers

5
HTML Page Execution
You Request an HTML Pagewww.cs.ucy.ac.cy/resumes.
htm
Server finds and downloads the page
Browser displays the page
6
ASP Page Execution
7
ASP Compared to Other Scripting Languages
  • ASP and /JSP/PHP/Perl/CGI execution are roughly
    equivalent in execution sequence
  • Compared to client-side VBScript, ASP does not
    have to worry about browser incompatibility
  • Compared to client-side JavaScript, dont have to
    worry about browser versions or disabling

8
ASP in the Microsoft Language Family
  • The ASP commands...

Visual Basic
VBScript
ASP
  • But theres more to ASP than just code...

9
ASP in the Microsoft Language Family
  • Some characterize ASP as more or less
    server-side VBScript
  • Arguments supporting this statement
  • Syntax is largely the same
  • Arguments against this statement
  • More security in connecting to Databases
  • More extensibility provided by the use of COM/DCOM

10
ASP in the Microsoft Language Family
  • ASP can also interact with other Microsoft
    languages or applications
  • Execute SQL commands
  • Open and close databases
  • Create and Modify database tables
  • Control applications or COM objects written or
    compiled in other languages (VB, C, Java)
  • Extract content from Excel or Word
  • Control an XML document

11
ASP Crash Course
  • Embedding ASP in HTML
  • Adding dynamic content
  • Variables and data types
  • Operators
  • Control Structures
  • ASP Objects
  • Forms handling and Querystrings
  • Session Handling
  • Session and application scope global.asa
  • Cookies

12
ASP Crash Course (cont.)
  • Embedding ASP in HTML
  • lthtmlgt
  • ltbodygt
  • ltstronggtHello World!lt/stronggtltbr /gt
  • lt
  • Response.Write ltbgtMy First ASP pagelt/bgt
  • gt
  • lt/bodygt
  • lt/htmlgt
  • Tagging
  • lt _at_LANGUAGE VBScript gt
  • ltgt
  • Script ltscript languageVBScript
    RUNATSERVERgtlt/scriptgt

13
ASP Crash Course (cont.)
  • Dynamically generated content
  • lt If Date() gt CDate("5/25/01") Then gt
  • ltpgtAnalytical Ultracentrifugation Workshop
    (May 21-23, 2001) and Symposium (May 24, 2001) at
    the National Analytical Ultracentrifugation
    Facility, Storrs, Conn. For additional
    informationlt/pgt
  • ltulgtltligtlta href"http//www.ucc.uconn.edu/www
    biotc/99wkshp.html" target"_blank"gtNational
    Analytical Ultracentrifugation Facilitylt/agtlt/ligt
  • ltligtlta href"naufworkshop.asp"gtAnalytical
    Ultracentrifugation Workshop and Symposium
    Description and Registration (PDF
    Format)lt/agtlt/ligt
  • lt/ulgt
  • lt End If gt

14
ASP Crash Course (cont.)
15
ASP Crash Course (cont.)
  • Including code/HTML into your page
  • lt
  • Set objRec Server.CreateObject("ADODB.Recordset
    ")
  • Set objConn Server.CreateObject("ADODB.Connecti
    on")
  • gt
  • lt!-- INCLUDE FILE "../adovbs.inc" --gt
  • lt!-- INCLUDE FILE "../connection.asp" --gt
  • lt
  • objRec.Open "Articles", objConn, adOpenKeyset,
    adLockOptimistic, adCmdTable
  • gt
  • Include file are executed before the scripts
  • Confidential info must be stored in files with
    .asp extension
  • Content can be included from a local or remote
    source

16
ASP Crash Course (cont.)
  • Variables
  • Variable names must begin with alphabetical
    character
  • Variable names must not contain embedded full
    stops
  • Variable names are case-insensitive
  • Max length 255
  • All variables have local scope
  • Example
  • Numberoftowns 6
  • Capital Nicosia

17
ASP Crash Course (cont.)
  • Data Types
  • As with many scripting languages ASP (VBScript)
    does not have explicit data types
  • Only one data type called Variant
  • Can store any data type
  • ASP automatically assigns subtypes to Variants
    i.e. numeric (integer, single, double), string,
    data, boolean and special
  • Forcing a data type by casting
  • strPi 3.142
  • intPi CInt(strPi)
  • dbPi CDbl(strPi)

18
ASP Crash Course (cont.)
  • Operators
  • Assignment (e.g. )
  • Arithmetic (e.g. , -, ,/)
  • Comparison (e.g. lt, gt, gt, ltgt)
  • Logical (e.g. AND, OR, NOT)
  • Arrays
  • One-Dimension Dim MyArray(10)
  • Multi-Dimension Dim MyMultiArray(10,10)

19
ASP Object Model
  • ASP itself is not Object-Oriented. ASP can use
    objects but cannot define new objects
  • Composed of
  • 5 objects
  • 5 components

20
ASP Objects
  • Built-in objects that allows for the following
  • Communicate with a Web browser
  • Gather data sent by HTTP request
  • Distinguish between users
  • Objects
  • Request
  • Response
  • Server
  • Application
  • Session

21
ASP Objects
  • Response Object
  • Sends information to client (HTML, text)
  • lt _at_LANGUAGE VBScript gt
  • lt
  • Option Explicit
  • gt
  • ltheadgt
  • lttitlegtA Simple ASP Examplelt/titlegt
  • lt/headgt
  • ltbodygt
  • ltpgtltstronggtA Simple ASP
    Examplelt/stronggtlt/pgt
  • lttable border "6"gt
  • lttrgtlttdgt
  • lt Response.write ltBgt FormatDateTime( Now,
    vbLongDate ) lt/Bgtgt
  • lt/tdgtlt/trgtlt/tablegt
  • lt/bodygt
  • lt/htmlgt

22
ASP Objects
  • Redirect to another page
  • ltif Request.Form("selection")ltgt"" then      
    Response.Redirect(thispage.asp)end ifgt 
  • Ending the execution of a page (and script)
  • lthtmlgtltbodygt
  • ltpgtI am writing some text. This text will never
    beltbrgt
  • lt
  • Response.End
  • gt
  • finished! It's too late to write more!lt/pgt
  • lt/bodygtlt/htmlgt

23
ASP objects
  • Request Object
  • Handles GET or POST information
  • Data provided by the user in an HTML form or
    passed by the querystring
  • Access to information stored on client machine
  • i.e. userlogin Request.Form(login)
  • i.e. selection Request.Querystring(selection)

24
ASP Objects Example
  • ltheadgt
  • lttitlegtName Requestlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltp style "font-family arial,
    sans-serif"gt
  • Enter your name
  • lt/pgt
  • lt!-- request name.asp when posted --gt
  • ltform action "name.asp" method
    "post"gt
  • ltinput type "text" name "namebox"
    size "20" /gt
  • ltinput type "submit" name
    "submitButton"
  • value "Enter" /gt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt

25
ASP Objects Example
  • lt _at_LANGUAGE VBScript gt
  • lt
  • ' Another simple ASP example
  • Option Explicit
  • gt
  • ltheadgt
  • lttitlegtName Informationlt/titlegt
  • ltstyle type "text/css"gt
  • p font-family arial,
    sans-serif
  • font-size 14pt color
    navy
  • .special font-size 20pt color
    green
  • lt/stylegt
  • lt/headgt
  • ltbodygt
  • lt!-- retrieve and display namebox's value
    --gt
  • ltpgtHi lt Response.write Request.Form(
    "namebox" ) gt, lt/pgtltbr /gt
  • ltp class "special"gtWelcome to ASP!lt/pgt
  • lt/bodygt
  • lt/htmlgt

26
ASP objects
  • How the information is handled
  • Main communication device between pages and the
    server is by Forms
  • Information can be transmitted or transferred
    from page to page in an application by
  • Submitting a form
  • Sending a URL-encoded string www.cs.ucy.ac.cy/m
    eetingadmin/edit.asp?ID5
  • Storing data as a Session variable

27
ASP Objects
  • Server Object
  • Provides access to server methods or properties
  • Examples
  • Create an instance of an ActiveX Component
  • ltSet objRecServer.CreateObject("ADODB.Recordse
    t")gt
  • Convert a virtual path to physical path
  • Server.MapPath(login.asp)
  • Perform HTML encoding
  • Server.HTMLEncode

28
ASP Objects
  • Application Object
  • An ASP application is a series of pages that are
    linked together through code
  • Application_OnStart Event Runs once when the
    first page of your application is run for the
    first time by any user
  • Application_OnEnd Event Runs once when the web
    server shuts down
  • Store application level variables (kind of
    Globals)
  • All must be done within the global.asa file
  • One per application
  • Placed at the root directory
  • Called when an application starts/ends

29
ASP Objects global.asa
  • Global.asa
  • ltSCRIPT LANGUAGE'VBScript' RUNAT'Server'gt
  • Sub Application_OnStart
  • application(connectionstring) DSNconn
  • End Sub
  • Sub Session_OnStart
  • Session(lng) EN
  • End Sub
  • lt/SCRIPTgt

30
ASP objects
  • Session Object Session Handling
  • Web is stateless/connectionless
  • Need a way to track information per user
  • Session ID
  • randomly generated
  • stored as a cookie on the clients browser
  • security issues (session hijacking)
  • Stored on the web server
  • Session_OnStart Initiates when user establishes
    connection
  • Session_OnEnd Expires when user closes
    connection
  • Set in the Global.asa

31
ASP Objects
  • Use Session Object to
  • Be notified when a user session starts
  • Be notified when a user session ends
  • Store user-specific information (very important)
  • Example
  • Page 1
  • ltSESSION(FName) Request.Form(FName)
  • SESSION(lName) Request.Form(lName)
  • gt
  • Page 2
  • lt
  • Response.Write SESSION(FName) . .
    SESSION(LName)
  • gt

32
ASP Cookies
  • For persistent cookies (set before the ltHTMLgt
    tag)
  • To write a cookie use
  • Response.Cookies(lang) EN
  • To retrieve a cookie use
  • Lang Request.Cookies(lang)
  • To set an expiration date
  • Response.Cookies(lang).Expires Date() 1
  • To delete a cookie
  • Response.Cookies(lang).Expires Date() - 1

33
ASP Components
  • Scripting Objects Component
  • File System
  • Dictionary
  • ADO (ActiveX Data Objects) Component
  • Connecting to Databases and data stores
  • Ad Rotator Component
  • Browser Capabilities Component

34
Connecting to databases
  • Primary reason why ASP technology was created
  • Two methods
  • Via ODBC
  • Via OLE-DB objects (faster)
  • Highly facilitated by ADO technology which stands
    above ODBC/OLE-DB
  • ASP can connect to virtually any data store

35
Terminology
  • ODBC Open Database Connectivity is a standard
    method of connecting an application or system to
    a database. Most database vendors provide ODBC
    drivers so that you can use ODBC as a method of
    connecting to and querying their database.
  • DSN Data Source Name is a joining point between
    the database server and any application wishing
    to query the database. Programs then wishing to
    connect to and query a database using ODBC can
    reference this DSN to point to the required
    database.
  • OLE-DB Microsoft alternative to ODBC its
    faster and is based on data consumers and data
    providers
  • ADO ActiveX Data Objects is a Microsoft to hide
    all the complexities of OLE-DB and ODBC and is
    what we use to store and retrieve information
    from data stores

36
Connection Strings
  • DSN requires DSN
  • DSN Contacts UIDweb_user PWDnone
  • DSN-less (MS Access)
  • DriverMicrosoft Access Driver (.mdb)
  • DBQC\inetpub\wwwroot\MyWeb\Contacts.mdb
  • DSN-less (MS SQL Server)
  • DriverSQL Server ServerSQLServer
    DatabaseContacts UIDweb_user PWDnone

37
Objects
  • Three basic objects
  • Connection
  • Handles the retrieval and storage to the
    datastore Set objConn Server.CreateObject("ADO
    DB.Connection")
  • Command
  • Handles the retrieval and storage to the
    datastore with extended functionality (stored
    procedures with data types)
  • Set objCommand Server.CreateObject("ADODB.Comm
    and")
  • Recordset
  • Contains the set of data retrieved from the
    database
  • Set objRec Server.CreateObject("ADODB.Recordse
    t")

38
  • lthtmlgt
  • ltheadgtltTITLEgtLogin Pagelt/TITLEgt
  • ltmeta http-equiv"Content-Type"
    content"text/html charsetwindows-1252"gt
  • ltLINK href"style.css" relstylesheet
    titleunit_style typetext/cssgt
  • ltbase target"main"gtltBASE target_selfgtlt/headgt
  • ltBODY bgColorffffddgtltPgtltBRgtlt/pgt
  • ltUserLogin Request.Form("UserLogin")
  • UserPassword Request.Form("UserPassword")
  • ' Validate Nulls
  • If IsNull(UserLogin) OR IsEmpty(UserLogin) Then
  • Response.Write "You did not enter your Login
    Name"
  • Else
  • Set objConn Server.CreateObject("ADODB.Connecti
    on")
  • Set objRec Server.CreateObject("ADODB.Recordse
    t")gt
  • lt!-- INCLUDE FILE "connection.asp" --gt
  • lt!-- INCLUDE FILE "adovbs.inc" --gt
  • lt
  • SQLstr"Select from Users Where user_Username
    '" UserLogin "'"
  • objRec.Open SQLstr, objConn, adOpenKeyset,
    adLockReadOnly, adCmdText





ltobjConn.Open "DSNcms_datagt
39
  • Set Conn Server.CreateObject("ADODB.Connection")
  • Conn.Open DSNTOPDB"
  • SqlStr "Select from tblCompany WHERE
    CompanysName'" Session("CName") "'"
  • SET RS Server.CreateObject("ADODB.Recordset")
  • RS.ActiveConnection Conn
  • RS.open sqlStr , objConn, adOpenKeyset,
    adLockReadOnly, adCmdText
  • If Not (RS.EOF) Then
  • str "ltligtltfont color3333FFgtltbgtCompany name
    already exists! Please choose another
    one.lt/bgtlt/fontgtlt/ligt "
  • showError str, "Add_Company.asp"
  • Response.End
  • End if
  • Set objCommand Server.CreateObject("ADODB.Command
    ")
  • strConnect DSNTOPDB"
  • objCommand.ActiveConnection strConnect

Add records to database Method using Command
object
40
  • ltSet objConn Server.CreateObject("ADODB.Connect
    ion")
  • Set objRec Server.CreateObject("ADODB.Recordset"
    )gt
  • lt!-- INCLUDE FILE "adovbs.inc" --gt
  • lt!-- INCLUDE FILE "connection.asp" --gt
  • lt
  • if request.querystring("task") addnew" then
  • objRec.Open "Customers", objConn, adOpenKeyset,
    adLockOptimistic, adCmdTable
  • objRec.AddNew
  • objRec("cus_FName") Request.Form("FName")
  • objRec("cus_LName") Request.Form("LName")
  • objRec("cus_Address") Request.Form("Address")
  • objRec("cus_Town") Request.Form("Town")
  • objRec("cus_Country") Request.Form("Country")
  • objRec("cus_Email") Request.Form("Email")
  • objRec("cus_login") Request.Form("UserName")
  • objRec("cus_Password") Request.Form("Password")

Insert record into database Method using ADO
41
Tools You Need to Create ASP Applications
  • Web Server that Supports ASP
  • Microsoft Internet Information Server (IIS)Web
    services of Windows NT Server 4.0 and Windows
    2000 Server
  • Microsoft Personal Web Server (PWS) Creates a
    fully functional subset of IIS 4.0 that can run
    on all other Windows OS
  • PWS is an add-on for Windows NT, 95/98/Me
  • Built-in to Windows 2000/XP PROFESSIONAL
  • Fundamental knowledge of Visual Basic

42
Tools You Need to Create ASP Applications
  • If you are working with database
    storage/retrieval
  • Knowledge of Access, SQL Server, etc. (to create
    databases and tables)
  • Knowledge of SQL commands (or at least how to use
    Access to generate SQL statements)
  • Knowledge of the VB style of data handling (ADO)
  • Authoring tool(s)

43
ASP Application Development Tools
  • Development Tools
  • Microsoft Visual InterDev
  • Visual Studio .NET
  • Microsoft FrontPage
  • Visual Basic
  • Microsoft Access
  • Other Non-Microsoft Tools (editors)

44
Steps to start developing
  • Create Web application in Internet Information
    Server (IIS)
  • Create MS Access Database
  • Create ODBC to point to MS Access
  • Open application with Microsoft FrontPage or any
    other tool to prepare layout
  • Open application with Visual InterDev or any
    other tool (FrontPage) for writing code
  • Test application using the browser

45
Create Web application in Internet Information
Server (IIS)
  • Create a folder with your application name in
    C\inetpub\wwwroot
  • Go to IIS Control Panel-gtAdministrative
    Tools-gtInternet Information Server
  • Find folder created -gtGo to Properties
  • Click on create application - Sample
  • Create a test page and test that application is
    working http//localhost/hw1/test.asp

46
Create MS Access Database
  • Create a new Access database
  • Save into a folder outside the Web Root (for
    security reasons not required for the
    assignment)
  • Give write permissions to the database file for
    the anonymous user (IUSR-ComputerName)- sample

47
Create ODBC to point to MS Access
  • Go to Control Panel-gtAdministrative Tools-gtData
    Sources (ODBC)
  • Create a System DSN
  • Give it a meaningful DSN name

48
Open application with Microsoft FrontPage
  • Start FrontPage
  • Go to File-gtOpen Web
  • Type http//localhost/hw1
  • Might be necessary to convert folder to web
  • WYSIWYG Microsoft Word style

49
Open application with Visual InterDev for writing
code
  • Visual InterDev is a part of Microsoft Visual
    Studio 6
  • Alternatively use FrontPage or Notepad

50
Test application using the browser
  • http//localhost/hw1

51
ASP Reference Tools
  • Microsoft Web Site (www.microsoft.com)
  • Knowledge Base for different Microsoft products
    and Web developer issues
  • MSDN (Microsoft Developer Network) Web site for
    subscribers and/or owners of VStudio
  • Google or other search engines
  • http//www.asptoday.com
  • http//www.4GuysFromRolla.com
  • http//www.aspfree.com

52
ASP Reference Tools
  • ASP Reference Books
  • ASP Developers Guide, by Greg BuczekISBN
    0-07-212274-3
  • Beginning Active Server Pages, by Francis et
    alISBN 1-861001-34-7
  • Professional Active Server Pages, by Francis et
    alISBN 1-861001-26-6

Online version of this book is on the Microsoft
Web sitehttp//www.microsoft.com/TechNet/iis/book
s.asp
53
ASP Reference Tools
  • ASP Reference Books (continued)
  • Using Active Server Pages, by Scot JohnsonISBN
    0-7897-1389-6
  • VBScript
  • VBScript Unleashed, by Petrousos, Schongar et
    alISBN 1-57521-124-6

54
Major Sites Using ASP
  • Microsoftwww.microsoft.com
  • NASDAQwww.nasdaq.com
  • Beckman Coulterwww.beckmancoulter.com
  • PC-Mac Connectionwww.pcconnection.com
  • Ticketmasterwww.ticketmaster.com
  • State Farm and Allstate Ins. Companieswww.statefa
    rm.com / www.allstate.com

55
Myths/Criticisms of ASP
  • ASP is Microsoft/Windows centric
  • ASP doesnt work with Netscape
  • ASP pages are not recognized by Search Engines
  • ASP is slow because its interpreted (or
    because its Microsoft)
  • ASP doesnt work with client-side scripting
    languages, especially JavaScript

56
Conclusion
  • ASP is another tool in your arsenal to control
    information
  • ASP may lead you to the dark side programming
    mainly a script language
  • Future of ASP What Lies BeneathMicrosoft
    FrameWork.NET, a successor to Visual Studio
    compiled ASP

57
Questions?
58
(No Transcript)
59
(No Transcript)
About PowerShow.com