private Sub WebClass_Start()
Dim sQuote As String
sQuote = Chr$(34)
'Write a reply to the user
With Response
.Write "<HTML>"
.Write "<body>"
.Write "<h1><font face=" & sQuote & "Arial" & sQuote & _
">This is the simplest thing you can do with a WebClass</font></h1>"
.Write "</body>"
.Write "</html>"
End With
End Sub
Figure 7 HelloWeb.asp
<%
Server.ScriptTimeout=600
Response.Buffer=True
Response.Expires=0
If (VarType(Application("~WC~WebClassManager")) = 0) Then
Application.Lock
If (VarType(Application("~WC~WebClassManager")) = 0) Then
Set Application("~WC~WebClassManager") = Server.CreateObject("WebClassRuntime.WebClassManager")
End If
Application.UnLock
End If
Application("~WC~WebClassManager").ProcessNoStateWebClass _
"prjHelloWeb.HelloWeb",
Server, _
Application, _
Session, _
Request, _
Response
%>
Figure 9 WCSongs WebClass
Option Compare Text
Dim curID
Dim songz As Database
Dim rsSongs As Recordset
Dim rsComm As Recordset
Private Sub tplAddComm_Form1()
Dim newID, newcomm
newID = Request.Form("hiddenID")
newcomm = Request.Form("edtComm")
If Len(newcomm) > 0 Then
Set songz = OpenDatabase(App.Path & "\BadSongs.mdb")
Set rsComm = songz.OpenRecordset("Comments", dbOpenDynaset)
rsComm.FindFirst ("SongID=" & newID)
With rsComm
If Not IsNull(rsComm!Comment) Then
.AddNew
!SongID = newID
Else
.Edit
End If
!Comment = Request.Form("edtComm")
.Update
.Bookmark = .LastModified
End With
rsComm.Close
songz.Close
End If
Response.Redirect "/BadSongs/WCSongs.ASP"
End Sub
Private Sub tplAddComm_ProcessTag(ByVal TagName As String, TagContents As String, SendTags As Boolean)
Dim st, rc
curID = Request.Item("id")
Set songz = OpenDatabase(App.Path & "\BadSongs.mdb")
Set rsSongs = songz.OpenRecordset("GetSongs")
Set rsComm = songz.OpenRecordset("GetComments")
rsSongs.FindFirst("ID=" & curID)
If rsSongs.NoMatch then Exit Sub
rsComm.FindFirst ("ID=" & curID)
Select Case TagName
Case "WC@SongName":
TagContents = rsSongs("Song").Value
Case "WC@Artist":
TagContents = rsSongs("Artist").Value
Case "WC@Hidden":
TagContents = "<input type=""hidden"" name=""hiddenID"" value=" & curID & ">"
Case "WC@OldComm":
If (IsNull(rsComm("Comment").Value)) Then
TagContents = "(none)"
Else
TagContents = rsComm("Comment").Value
End If
End Select
End Sub
Private Sub tplAddComm_Respond()
tplAddComm.WriteTemplate
End Sub
Private Sub WebClass_Start()
curID = Request.Item("id")
Set songz = OpenDatabase(App.Path & "\BadSongs.mdb")
Set rsSongs = songz.OpenRecordset("Songs")
Set rsComm = songz.OpenRecordset("GetComments")
tplAddComm.WriteTemplate
End Sub
Figure 11 Standard ASP Objects
Request | |
This class contains methods that enable your component to use the methods, properties, and collections of the Request object. Methods |
|
ClientCertificate as IRequestDictionary | Collection of client certificate fields (specified in the X.509 standard). |
Cookies as IRequestDictionary | Collection of cookies sent as part of the request (read-only). |
Form as IRequestDictionary | Collection of form elements. |
QueryString as IRequestDictionary | Collection of query string values. |
ServerVariables as IRequestDictionary | Collection of predetermined environment variables. |
BinaryRead as Safe Array | Reads data sent to the server from the client as part of a POST request. |
TotalBytes as Variant | Specifies the total number of bytes the client sent in the body of the request. |
Collections | |
ClientCertificate | The values of fields stored in the client certificate that is sent in the HTTP request. |
Cookies | The values of cookies sent in the HTTP request. |
Form | The values of form elements in the HTTP request body. |
QueryString | The values of variables in the HTTP query string. |
ServerVariables | The values of predetermined environment variables. |
Application | |
This class contains methods that enable your component to call the methods, properties, and collections of the Application object. Method |
|
Lock | Prevents other scripts from modifying variables stored in the Application object. |
Unlock | Enables other scripts to modify variables stored in the Application object. |
Collections | |
Contents | Contains all of the items that have been added to the session through script commands. |
StaticObjects | Contains all of the objects added to the session with the <OBJECT> tag. |
Response | |
This class contains methods that enable your component to use the methods, properties, and collections of the Response object. Methods |
|
AddHeader | Adds an HTTP header. |
AppendToLog | Adds a string to the end of a Web server log entry for this request. |
BinaryWrite | Writes content without any character conversion (Unicode to ANSI). |
Buffer | Indicates whether page output is buffered. |
CacheControl | Overrides the Private default value. By setting this property to Public, proxy servers will be able to cache the output generated by ASP. |
Charset | Appends the name of the character set (for example, ISO-LATIN-7) to the content-type header in the Response object. |
Clear | Erases any buffered output. |
ContentType | The HTTP content type. |
Cookies | Write-only. Collection of cookies sent as part of the response. |
End | Causes ASP to stop processing and return any buffered output. |
Expires | The length of time in minutes until the response expires. |
ExpiresAbsolute | The absolute date and time that the response expires. |
Flush | Sends buffered output immediately. |
IsClientConnected | Indicates if the client has disconnected from the server since the last Response.Write. |
PICS | Adds a value to the PICS-label field of the response header. |
Redirect | Sends a 302 Redirect status line. |
Status | The HTTP server status line. |
Write | Writes content with character conversion (Unicode to ANSI). |
Collection | |
Cookies | Specifies cookie values. Using this collection, you can set cookie values. |
Server | |
This class contains methods that enable your component to use the methods, properties, and collections of the Server object. Methods |
|
CreateObject | Creates an instance of a server component. |
HTMLEncode | Applies HTML encoding to a specified string. |
MapPath | Maps the specified relative or virtual path to the corresponding physical directory on the server. |
ScriptTimeout | The maximum length of time in seconds before a script is terminated. |
URLEncode | Applies URL encoding rules, including escape characters, to a specified string. |
Session | |
This class contains methods that enable your component to use the methods, properties, and collections of the Session object. Methods |
|
Abandon | Destroys a Session object and releases its resources. |
CodePage | Determines the codepage that will be used to display dynamic content. |
LCID | Specifies the locale identifier, which is a standard international abbreviation that uniquely identifies one of the system-defined locales. |
SessionID | Returns the session identifier of the user. |
Timeout | The length of time, in minutes, of the Timeout period. |
Collections | |
Contents | Contains all of the items that have been added to the session through script commands. |
StaticObjects |
Contains all of the objects added to the session with the <OBJECT> tag. |
Figure 12 Bad Songs 2000
Figure 13 BS2K Form Code
<form action="addsong.ASP?WCI=tplAddNew&WCE=Form1&WCU" method="post">
<p><font face="Verdana">Song: <input type="text" size="20"
name="edtSong"> Artist: <input type="text" size="20"
name="edtArtist"></font></p>
<p><font face="Verdana">Year: <input type="text" size="20"
name="edtYear"></font></p>
<p><font face="Verdana">Comment: </font><input type="text"
size="128" name="edtComment"></p>
<p><input type="submit" name="btnAdd" value="Add!"> <input
type="reset" name="btnClear" value="Clear"><input
type="button" name="btnBack" value="Back"></p>
</form>
<script language="VBScript">
Sub btnBack_onclick()
window.history.back()
end sub
</script>
Figure 14 WCAddSong
Option Explicit
Option Compare Text
Dim songz As Database
Dim rsSongs As Recordset
Dim rsAvg As Recordset
Dim rsComm As Recordset
Private Sub tplAddNew_Form1()
On Error Resume Next
Dim req As Variant
Dim conn As Connection
Dim SQL As String
Dim RS As Recordset
If Len(Request.Form("edtSong")) > 0 Then
' Open Databases/Recordsets used in the form response
Set songz = OpenDatabase(App.Path & "\BadSongs.mdb")
Set rsSongs = songz.OpenRecordset("Songs")
Set rsComm = songz.OpenRecordset("Comments")
' Add the record to the Songs table
With rsSongs
.AddNew
!Song = Request.Form("edtSong")
!Artist = Request.Form("edtArtist")
!SongYear = CLng(Request.Form("edtYear"))
.Update
.Bookmark = .LastModified
End With
' Add comments to the Comments table
With rsComm
.AddNew
!SongID = rsSongs("ID").Value
!Comment = Request.Form("edtComment")
.Update
.Bookmark = .LastModified
End With
rsSongs.Close
rsComm.Close
songz.Close
End If
Response.Redirect "WCSongs.ASP"
End Sub
Private Sub tplAddNew_Respond()
End Sub
Private Sub WebClass_Start()
tplAddNew.WriteTemplate
End Sub
Sub WriteChartHeader()
Dim f, td, CRLF
CRLF = Chr$(13) & Chr$(10)
f = "<font size=""2"" face=""Verdana"">"
td = "<td align=""left"" valign=""top"">"
With Response
.Write "<p><form method=""POST"" name=""frmBadSongs"">"
.Write "<table border=0 cellspacing=0>"
.Write "<tr>"
.Write td & f & "<strong>Song</strong></font></td>" & CRLF
.Write td & f & "<strong>Artist</strong></font></td>" & CRLF
.Write td & f & "<strong>Year</strong></font></td>" & CRLF
.Write td & f & "<strong>Comment</strong></font></td>" & CRLF
.Write "</tr>"
f = "<font size=""1"" face=""Verdana"">"
End With
End Sub