Download presentation
Presentation is loading. Please wait.
1
Dynamic Web Sites DECO 3001 Tutorial 6 – Email Form Presented by Ji Soo Yoon 30 April 2004 Slides adopted from http://aurora.wells.edu/~ccs/cs310/02/cs310.htm, http://csp.ipm.edu.mo/teachers/philip/mccs352/ppt/asp.ppt, http://www.w3schools.com/asp/default.asp, and A Practical Guide To Active Server Pages 3.0 ©2000 Manas Tungarehttp://aurora.wells.edu/~ccs/cs310/02/cs310.htm http://csp.ipm.edu.mo/teachers/philip/mccs352/ppt/asp.ppt http://www.w3schools.com/asp/default.asp
2
Active Server Pages Revisited An Active Server Page is a text script with extension.asp An ASP typically contains HTML, client and server scripts ASP code is bracketed in Pre-processed (like SSIs) before the page is sent to the client Statements in VBScript (similar to VB) or in JavaScript Uses built-in ASP objects Uses prewritten active server components (called COM objects stored in.dll or.exe files) Can build new COM objects (harder)
3
“Hello World” Example <% Dim I ' declare our loop index variable %> <% For I = 1 To 5 Step 1 %> ” >Hello World <% Next ' bounce back to the top of the loop %>
4
Advantages Easier to code Faster execution with multiple hits Each CGI program loads separate code Two ASP pages can use the same.dll file which is loaded only once Expected availability of Microsoft and third party COM objects Can be developed in (almost) any language Fostered by Microsoft
5
Disadvantages Evolving rapidly Hard to gain detailed information of different components Fostered by Microsoft
6
Intrinsic Objects ASP programs have access to intrinsic objects Request Response Application Session Server Each of the objects has a set of collections, methods, properties and events which provide them with all their functionality
7
Request Object Information returned with the HTTP header (GET) or body (POST) Properties TotalBytes (the size of data in HTTP header) Collections ClientCertificate (for security) Cookies Form QueryString ServerVariables
8
Request.QueryString The information sent using GET Request.QueryString is everything after the ? Request.QueryString("name") Gets value for http://www.xxx.yyy?name=value. If this is from a form, it will be associated with an input box with NAME= name
9
Request.Form The information sent from a form via POST Request.Form(“name”) gets the value assigned to an input box with NAME= name
10
Request.ServerVariables Environment variables in HTTP header CGI equivalent: environment variables See http://aurora.wells.edu/~cs330/scripts/env 2.cgi
11
Response Object Control over information sent to the client in the HTTP response: when, how, what Properties Buffer, CacheControl, Charset, ContentType, Expires,... Collections Cookies Methods AddToHeader, AppendToLog, Clear, End, Flush, Redirect Write (most frequently-used)
12
Other Intrinsic Objects Application An application is all files that can be accessed through a directory and its subdirectories Allows variables and objects with application-level scope Application_OnStart event when first client requests a file Session Tracks the current user’s info, Initialized via Session_OnStart Server Properties: ScriptTimeout Methods: CreateObject, HTMLEncode, MapPath, URLEncode Server.ScriptTimeout = 100 Server.CreateObject(“ADODB.Connection”))
13
Installable Components ASP programs have access to intrinsic objects (Request, Response, Application, Session, Server) Other objects can be “installed” Standard library Built for a particular application COM is the interface standard for these objects which have methods and properties Examples: Collaboration Data Objects: CDONTS ActiveX Data Objects: ADODB Others: Ad Rotator, Content Linking, Content Rotator, Counters, File Access, Page Counter, Permission Checker
14
Collaboration Data Objects (CDO) CDO adds messaging functions to applications. CDONTS is a COM library for NT designed to send mail through SMTP To create the CDONTS object Dim objCDOMail 'The CDO object Set objCDOMail = Server.CreateObject("CDONTS.NewMail") This has Attributes: From, To, Subject, Body, Cc, Bcc, AttachFile,... Method: Send Procedure: assign values to the attributes apply Send
15
Sending a simple message Dim objCDOMail Set objCDOMail = Server.CreateObject("CDONTS.NewMail") objCDOMail.To = “Receiver Email Address” objCDOMail.From = “Sender Email Address” objCDOMail.Subject = “Subject” objCDOMail.Body = “Body” objCDOMail.Send Set objCDOMail = Nothing
16
File Access Access to a file system via the FileSystemObject Server.CreateObject(“Scripting.FileSystemObjec t”) File system has folders, drives, files Methods: CreateFolder, CreateTextFile, DriveExists, DeleteFile, GetFile, OpenTextFile,... Text file methods: Read, ReadLine, Write,
17
ADO: Active Data Objects ADODB.Connection: to a data provider (db) ADODB.Recordset: the records returned from a query (or a whole table) ADODB.Field: a component in a recordset ADODB.Command: an SQL statement that returns a recordset ADODB.Parameter: holds parameters in an SQL statement ADODB.Error, ADODB.Property
18
Connection Object A connection to the database. Can be used for more than one query. Properties ConectionTimeout CommandTimeout ConnectionString Methods Open Close
19
Example Set DataConn = Server.CreateObject("ADODB.Connection") DataConn.ConnectionTimeout = 15 'property DataConn.CommandTimeout = 30 ‘property Note, this has no connection to any data yet. DataConn.Open "DBQ=" & Server.MapPath("database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}; DriverId=25; MaxBufferSize=8192; Threads=20;", "username", "password" An Access database, database.mdb on the default directory Fill in correct “username” and” password”
20
Recordset Object Records in a query or table from the connection It must be opened to have anything in it Properties ActiveConnection: the current data source Fields: in the table BOF, EOF: of the recordset Methods AddNew Delete MoveFirst, MoveNext, MoveLast Open, Close
21
Command Object Not necessary (one can just type in when a recordset is opened), but a neat way to define and reuse commands Properties CommandText CommandType (adcmdText = SQL, adcmdTable = table name, Methods Execute
22
File Access Access to a file system via the FileSystemObject Server.CreateObject(“Scripting.FileSystemObjec t”) File system has folders, drives, files Methods: CreateFolder, CreateTextFile, DriveExists, DeleteFile, GetFile, OpenTextFile,... Text file methods: Read, ReadLine, Write,
23
More ADODB Major objects: Connection and Recordset Possible interfaces to a database via a connection – previous slides directly – slides to come Recordset Connection Recordset DB Recordset
24
Comparison Connection Cleaner Allows multiple recordsets without recreating and duplicating the connection Easier to change in one place Just recordset Less code to write (not a good reason)
25
Using a connection Set DataConn =Server.CreateObject("ADODB.Connection") strConnString = "DRIVER={Microsoft Access Driver... DataConn.Open strConnString, strUserId, strPasswd Set rsObj = Server.CreateObject("ADODB.Recordset") cmdSQL = “SELECT…” rsObj.Open cmdSQL, DataConn, CursorType, LockType,.. The first param is an SQL statement, a table, procedure name The second param is a connection object or string with connection text
26
Using a recordset: With intermediate variables: strConnString = "DRIVER={Microsoft Access... Set rsObj= Server.CreateObject("ADODB.Recordset") rsObj.Open cmdSQL, strConnString, … More confusing, put everything in the Open command: rsObj.Open “SELECT…”, "DRIVER={Microsoft Access…”, …
27
ASP Components Components (e.g. ADODB) have classes e.g. Connection, Recordset, Field, Command,.. Classes have methods e.g. Open, Close,.. The ADODB.dll is available to ASP pages and supports this component An object is created in an ASP page with the create method of Server Server.CreateObject(“component_name.class_name”) objDataConn =Server.CreateObject(“ADODB.Connection”) The object then has access to the methods of the class
28
Developing components Most easily built in VB. Ref: Shelly Powers. Open VB Select File/New Project/ActiveX DLL You get Project1 and a Class1 window Change Project1 name to NewCom in Project/Properties Change Class1 name to CLA in the window for Class 1 Build functions for AddNew, Remove, … in the (Code) window Public Function AddNew() --------- End Function Make/Project creates NewCom.dll regsvr32 NewCom.dll registers it objCLA = Server.CreateObject(“NewCOM.CLA”) creates an instance
29
ASP Learning and Code Sites ASP Lessons http://www.learnasp.com/learnasp/ http://www.learnasp.com/learnasp/ ASP Tutorial http://www.w3schools.com/asp/ http://www.w3schools.com/asp/ ASP Tips www.4guysfromrolla.com www.4guysfromrolla.com ADO Connection String Samples http://www.able-consulting.com/ado_conn.htm?f=ado_conn.htm http://www.able-consulting.com/ado_conn.htm?f=ado_conn.htm Microsoft’s ASP Site http://msdn.microsoft.com/asp http://msdn.microsoft.com/asp Other ASP Sites http://www.learnasp.com/links/ http://www.learnasp.com/links/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.