Windows 2000 and ASP as Development Environment - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Windows 2000 and ASP as Development Environment

Description:

Active Server Pages ... Just click on 'save as' and scroll down to the Active Server Pages option ... Creates an instance of an Active server component ... – PowerPoint PPT presentation

Number of Views:290
Avg rating:3.0/5.0
Slides: 35
Provided by: norman5
Category:

less

Transcript and Presenter's Notes

Title: Windows 2000 and ASP as Development Environment


1
Windows 2000 and ASP as Development Environment
  • Norman White
  • 2001

2
IIS/ASP Integration with Office
  • IIS and Office are tightly integrated in Office
    2000
  • Office applications can be used to directly
    generate Web applications, including Data Base
    applications
  • Integration makes it a great development
    environment for prototyping
  • But first, what is ASP?

3
Active Server Pages
  • Concept is to have web pages that dynamically
    change (at the server) depending on external
    events (data, time, client, form inout etc).
  • ASP is Visual Basic Code embedded in the web page
    (like Javascript) and interpreted at the server
    before the page is delivered.

4
ASP Processing
  • Unlike CGI processing and some other approaches,
    the ASP processor is part of the IIS web server
    (just as javascript is part of the browser.
  • This means that the OS does not have to start up
    another application on every page.
  • If the page has an ASP extension, the web server
    will look for embedded ASP code.

5
ASP coding
  • Whenever the web server finds an ASP reference,
    it turns control over to ASP. The ASP processor
    executes the instructions and the returns control
    to the web server. Since the ASP processor is
    part of the web server, it can do things like
    generate HTML directly.
  • But it can also do almost anything you can do in
    VB, including data base access.

6
More ASPForms
  • Since ASP is part of the WEB server access to
    form information is much easier than most other
    approaches.
  • Var request.form(fieldname)
  • will place contents of field fieldname in
    Variable Var
  • (nicer than Unix shell huh?)

7
ASP and Office
  • Even better is the ability of Office to generate
    working ASP applications
  • Just click on save as and scroll down to the
    Active Server Pages option
  • Office will generate a set of ASP files that
    implements the application on the WEB using ASP.
  • Then move application to the web server and run

8
ASP and Databases
  • ASP accesses data bases using ODBC (Open Data
    Base Connectivity ) now called ADO (ActiveX Data
    Objects) and MDAC
  • The name keeps changing, but the concept is the
    same
  • Application Opens a data base connection to a
    local data object (which can point to remote
    data)
  • It then manipulates the data base

9
ODBC Naming
  • As long as the ODBC name is the same on the
    system you develop app and the web server,
    everything should run on the web server (or else
    you need to change the name)
  • To add an ODBC data source to a system,
  • Click on Start, Settings, Control Panel, ODBC
    Data Sources (32 bit)
  • Give the Data source a name, and then pick the
    database system, the server and the userid and
    password

10
(No Transcript)
11
Sample ASP file
  • lt_at_ LanguageVBScript gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtExample 1lt/titlegt
  • lt/headgt
  • ltbodygt
  • lt
  • FirstVar "Hello world!"
  • gt
  • ltFirstVargt
  • lt/bodygt
  • lt/htmlgt

12
Looping in ASP
  • lt_at_ LanguageVBScript gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtExample 2lt/titlegt
  • lt/headgt
  • ltbodygt
  • lt
  • FirstVar "Hello world!"
  • gt
  • ltFOR i1 TO 10gt
  • ltFirstVargt
  • ltNEXTgt
  • lt/bodygt
  • lt/htmlgt

13
Functions in ASP
  • lt_at_ LanguageVBScript gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtExample 3lt/titlegt
  • lt/headgt
  • ltbodygt
  • lt
  • FirstVar "Hello world!"
  • gt
  • The time is lttimegt ltBRgt
  • ltFOR i1 TO 10gt
  • ltFirstVargt
  • ltNEXTgt
  • lt/bodygt
  • lt/htmlgt

14
Conditional Execution in ASP
  • _at_ LanguageVBScript gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtExample 4lt/titlegt
  • lt/headgt
  • ltbodygt
  • ltIF Hour(time)gt18 OR Hour(time)lt4 THENgt
  • Good Night Everyone.
  • ltELSEgt
  • Good Morning Everyone.
  • ltEND IFgt
  • lt/bodygt
  • lt/htmlgt

15
Sample Form(from Microsoft ASP Tutorial)
  • lthtmlgt
  • ltheadgt
  • lttitlegtButton Formlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltFORM NAME"Button Example" METHOD"POST"
    ACTION"tutorial/button.htm"gt
  • Computer Programming Experience
  • ltPgt
  • ltINPUT TYPE"button" NAME"choice" VALUE"Less
    than 1"gtLess than 1 year.ltBRgt
  • ltINPUT TYPE"button" NAME"choice" VALUE"1 to
    5"gt1-5 years.ltBRgt
  • ltINPUT TYPE"button" NAME"choice" VALUE"More
    than 5"gtMore than 5 years.
  • lt/Pgt
  • ltPgtltINPUT TYPE"reset" VALUE"Clear Form"gt
  • ltINPUT TYPE"submit" VALUE"Submit"gt
  • lt/Pgt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt

16
Guestbook Application
  • Need to
  • Create Database using Access
  • I.e. create Table and fields
  • Move Data Base to web server or create database
    in c\inetpub\wwwroot\Tutorial\
  • (Default web server root)
  • Create ODBC DSN for Database
  • Create ASP application (guestbook.asp)

17
Guest Data Base fields
  • Field Name
  • Data Type and General
    Properties
  • ID
  • AutoNumber, Field
    SizeLong Integer, New ValuesIncrement,
  • IndexedYes(No
    Duplicates)
  • TB1
  • Text, Field Size255,
    RequiredNo, Allow Zero LengthYes,
  • IndexedNo
  • TB2
  • Text, Field Size255,
    RequiredNo, Allow Zero LengthYes,
  • IndexedNo
  • TB3
  • Text, Field Size255,
    RequiredNo, Allow Zero LengthYes,
  • IndexedNo
  • TB4
  • Text, Field Size255,
    RequiredNo, Allow Zero LengthYes,
  • IndexedNo
  • MB1
  • Memo, RequiredNo,
    Allow Zero LengthYes

18
Creating ODBC Data Source
  • 1.In the ODBC Data Source Administrator, select
    the ODBC icon.
  • 2.Select File DSN.
  • 3.Select Add, select Microsoft Access Driver,
    and click Next.
  • 4.Type in a descriptive name for your file DSN
    (Guestbook) and click Next.
  • 5.Click Finish, click Select, specify the
    location of the database file, and select OK.
  • 6.Click OK twice. After you specify the
    location of the database file, the ODBC Data
    Source Administrator creates a file DSN for
    it.

19
(No Transcript)
20
(No Transcript)
21
(No Transcript)
22
The Application LogicGuestbook.asp
  • See if Message field (hidden) is True
  • If true, retrieve field values and insert new
    entry into the database table
  • Message not True
  • If message is not true, generate the form
  • with a hidden field message TRUE
  • and have the action statement run Guestbook.asp
    (this asp file
  • Note, only one file
  • It either processes the input, or generates the
    form for the input.

23
Guestbook.ASP file(put in c\inetpub\wwwroot\Tuto
rial)
  • lt _at_LanguageVBScript gt
  • lthtml dirltrgt
  • ltheadgt
  • ltTITLEgtGuest Booklt/TITLEgt
  • lt/headgt
  • ltbody bgcolor"FFFFFF" text"000000"gt
  • lt
  • IF request.form ("Message")"True" THEN
  • strTB1request.form("To")
  • strTB2request.form("EMailAdd")
  • strTB3request.form("CC")
  • strTB4request.form("Subject")
  • strMB1request.form("Memo")
  • IF strMB1 "" THEN
  • iLenMB1255
  • ELSE
  • iLenMB1 Len(strMB1)
  • END IF

24
Create the Database connection
  • Connects to the Access driver and Access
    database in the Inetpub
  • directory where the database is saved
  • strProvider "DriverMicrosoft Access Driver
    (.mdb) DBQC\Inetpub\Wwwroot\Tutorial\guestboo
    k.mdb"
  • Creates an instance of an Active Server
    component
  • set objConn server.createobject("ADODB.Connect
    ion")
  • Opens the connection to the data store
  • objConn.Open strProvider
  • Instantiate Command object and use
    ActiveConnection property to
  • attach connection to Command object
  • set cm Server.CreateObject("ADODB.Command")
  • cm.ActiveConnection objConn

25
Create an SQL Query
  • Define SQL query
  • cm.CommandText "INSERT INTO Guestbook
    (TB1,TB2,TB3,TB4,MB1) VALUES (?,?,?,?,?)"
  • Define query parameter configuration
    information for guestbook fields
  • set objparamcm.createparameter(, 200, , 255,
    strTB1)
  • cm.parameters.append objparam
  • set objparamcm.createparameter(, 200, , 255,
    strTB2)
  • cm.parameters.append objparam
  • set objparamcm.createparameter(, 200, , 255,
    strTB3)
  • cm.parameters.append objparam
  • set objparamcm.createparameter(, 200, , 255,
    strTB4)
  • cm.parameters.append objparam
  • set objparamcm.createparameter(, 201, ,
    iLenMB1, strMB1)
  • cm.parameters.append objparam
  • cm.execute
  • response.write("Thank you!")

26
Handle New Entries
  • ELSEgt
  • lth1gtGuestbooklt/h1gt
  • lt!--Post information to Guestbook form --gt
  • ltform nameguestbook.asp action"guestbook.asp"
    method"POST"gt
  • ltpgtTolt/pgt
  • ltpgtltinput type"Text" name"To"gtlt/pgt
  • ltpgtEmail Addresslt/pgt
  • ltpgtltinput type"Text" name"EmailAdd"gtlt/pgt
  • ltpgt CClt/pgt
  • ltpgtltinput type"Text" name"CC"gtlt/pgt
  • ltpgtSubjectlt/pgt
  • ltpgtltinput type"Text" name"Subject"gtlt/pgt
  • ltpgtMessagelt/pgt
  • ltpgtlttextarea name"Memo" rows6
    cols70gtlt/textareagtlt/pgt
  • ltinput type"HIDDEN" name"Message"
    value"True"gt
  • ltinput type"submit" value"Submit
    information"gt
  • lt/formgt
  • ltEnd ifgt
  • lt/bodygt

27
So, How hard is that?
  • Not too bad, but how does someone look at the
    guestbook?
  • Need another ASP file to view entries
  • Nice to allow users to sort entries...

28
Viewing Program
  • lt _at_LanguageVBScript gt
  • lthtml dirltrgt
  • ltheadgt
  • lttitlegtView Guest Booklt/titlegt
  • lt/headgt
  • ltbody bgcolor"FFFFFF" text"000000"gt
  • lt
  • This section makes it possible for visitors to
    sort the data in the columns in ascending order.
  • if request.form("sort")ltgt "" THEN
  • StrSortrequest.form("sort")
  • ELSE
  • StrSort"TB1 ASC"
  • END IF

29
Connect to Guestbook and create query
  • strQuery"SELECT FROM Guestbook ORDER BY "
    StrSort
  • Database path statement describing the driver
    to use and the path to the desired database.
  • strProvider "DriverMicrosoft Access Driver
    (.mdb) DBQC\Inetpub\Wwwroot\Tutorial\guestbook
    .mdb"
  • IF Request("ID") ltgt "" THEN
  • strIDNumRequest("ID")
  • Creates an instance of an Active server
    component
  • set objConn server.createobject("ADODB.Connect
    ion")
  • Opens the connection to the data store
  • objConn.Open strProvider
  • Instantiate Command object and use
    ActiveConnection property to
  • attach connection to Command object
  • set cm Server.CreateObject("ADODB.Command")
  • cm.ActiveConnection objConn

30
  • Define SQL query
  • cm.CommandText "DELETE FROM Guestbook WHERE
    ID " strIDNum
  • cm.Execute
  • END IF
  • Instantiate a Recordset object and open a
    recordset using
  • the Open method
  • Set rst Server.CreateObject("ADODB.recordset")
  • rst.Open strQuery, strProvider
  • gt

31
  • lth1gtGuest Booklt/h1gt
  • ltform nameviewdb.asp actionviewdb.asp
    methodpostgt
  • lttable border1 cellspacing3 cellpadding3
    rulesboxgt
  • lt
  • ON ERROR RESUME NEXT
  • IF rst.EOF THEN
  • Response.Write "There are no entries in the
    database."
  • ELSEgt
  • lttrgt

32
  • lt
  • Deletes rows from the database, this cannot be
    undone
  • Response.Write "lttd width200gtltcentergtDelete
    Recordlt/centergtlt/tdgt"
  • FOR i 1 to rst.Fields.Count -1
  • Response.Write "lttd width200gtltinput namesort
    value" rst(i).Name " typesubmitgtlt/tdgt"
  • NEXT
  • WHILE NOT rst.EOF gt
  • lttrgt
  • lt
  • Response.Write "lttd alignleft valigntop
    bgcolorffffffgtlta hrefviewdb.asp?id"
    rst(0) "gtDeletelt/agtlt/tdgt"
  • FOR i 1 to rst.fields.count - 1
  • Response.Write "lttd alignleft valigntop
    bgcolorffffffgt" rst(i) "lt/tdgt"
  • NEXT
  • rst.MoveNext
  • WEND
  • END IF
  • gt
  • lt/tablegt
  • lt/formgt

33
What is happening?What does the code do?
  • Hint, What do you think the name of the asp file
    is?

34
Conclusion
  • Win2K fast development environment
  • Integrated with Office
  • BUT
  • Win2K still not a mature platform
  • Needs
  • Something like a standard shell language
  • Batch queues with priorities
  • Priority for different applications etc.
  • Excellent system for small medium businesses.
  • Still problematical for very large sites, but
    moving fast.
Write a Comment
User Comments (0)
About PowerShow.com