Email slides

Download Report

Transcript Email slides

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 Tungare
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)
“Hello World” Example
<%
Dim I
%>
' declare our loop index variable
<%
For I = 1 To 5 Step 1
%>
<FONT SIZE= "<%= I %>” >Hello World</FONT><BR>
<%
Next
%>
' bounce back to the top of the loop
Advantages


Easier to code
Faster execution with multiple hits



Expected availability of Microsoft and third
party COM objects


Each CGI program loads separate code
Two ASP pages can use the same .dll file which
is loaded only once
Can be developed in (almost) any language
Fostered by Microsoft
Disadvantages



Evolving rapidly
Hard to gain detailed information of
different components
Fostered by Microsoft
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
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
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
Request.Form


The information sent from a form via
POST
Request.Form(“name”) gets the value
assigned to an input box with NAME=
name
Request.ServerVariables


Environment variables in HTTP header
CGI equivalent: environment variables

See
http://aurora.wells.edu/~cs330/scripts/env
2.cgi
Response Object


Control over information sent to the client in
the HTTP response: when, how, what
Properties


Collections


Buffer, CacheControl, Charset, ContentType,
Expires, ...
Cookies
Methods


AddToHeader, AppendToLog, Clear, End, Flush,
Redirect
Write (most frequently-used)
Other Intrinsic Objects

Application




Session


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
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”))
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

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
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
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,
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
Connection Object


A connection to the database. Can be
used for more than one query.
Properties




ConectionTimeout
CommandTimeout
ConnectionString
Methods


Open
Close
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”
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
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
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,
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
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)
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
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…”, …
ASP Components

Components (e.g. ADODB) have classes


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



e.g. Connection, Recordset, Field, Command,..
Server.CreateObject(“component_name.class_name”)
objDataConn =Server.CreateObject(“ADODB.Connection”)
The object then has access to the methods of the class
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
ASP Learning and Code Sites

ASP Lessons


ASP Tutorial


http://www.able-consulting.com/ado_conn.htm?f=ado_conn.htm
Microsoft’s ASP Site


www.4guysfromrolla.com
ADO Connection String Samples


http://www.w3schools.com/asp/
ASP Tips


http://www.learnasp.com/learnasp/
http://msdn.microsoft.com/asp
Other ASP Sites

http://www.learnasp.com/links/