ASP is a server-side technology that can use server
and client information in order to deliver dynamically created XHTML documents
to the client (user). VBScript is the most widely used language in which to implement ASP, but JavaScript and other languages can be used instead.
ASP scripts are interpreted on the server by a scripting engine, which is most often
a Microsoft proprietary ActiveX component with the file name asp.dll.
When an ASP file is requested by a user, the scripting engine interprets the code in the file.
Most often, the code generates XHTML code, which is sent to the user and interpreted as an
XHTML document by the user's browser.
ASP has several objects that afford programmers access to user browser information, and
user information submitted by GET or POST form methods,
that can send XHTML code to a user and that can access server information. ASP also has File System Objects that represent files, folders, drives,
and streams and a wide number of methods for each type of object.
For this example, we will refer to the following XHTML document which contains a form. The action of the form is an ASP document named submit-info.asp. Please familiarize yourself with the following form and then continue below.
<html>
<head>
<title>Personal Information</title>
</head>
<body>
<form action = "submit-info.asp" method = "post">
First Name:
<input type = "text" name = "fname" size = "20" />
<br />
Last Name:
<input type = "text" name = "lname" size = "20" />
<br />
Street Address:
<input type = "text" name = "straddress" size = "40" />
<br />
City:
<input type = "text" name = "city" size = "30" />
<br />
State:
<input type = "text" name = "state" size = "30" />
<br />
Zip:
<input type = "text" name = "zip" size = "15" />
<br />
<input type = "submit" name = "submitButton" value = "Enter" />
</form>
</body>
</html>
The ASP file referred to in the XHTML form above is listed in its entirety below.
It is really a combination of VBScript and XHTML. VBScript that is executed
on the server is enclosed in <%…%> delimiters. Code within these delimiters is
not executed on the client end, as is normally done with VBScript or JavaScript,
but is executed on the server. The first line in the file with @LANGUAGE = VBScript,
indicates to the server, that the script in this file is VBScript. If this line is omitted, the
server will default to VBScript. Alternatively, JavaScript might be used as the scripting
language. The next line contains the VBScript Option Explicit , command which is
discussed in the section about VBScript, but, in short it indicates that the programmer
will be explicitly declaring all of the variables used in the script. Look at the code below.
Further explanation of the code follows.
<% @LANGUAGE = VBScript %>
<%
' submit-info.asp
Option Explicit
%>
<html>
<head>
<title>Information Submitted</title>
</head>
<body>
<%
Dim NewMail, Message
Message = "First Name: " & Request( "fname") &_
"\n" & "Last Name: " & Request( "lname") &_
"\n" & "Street: " & Request( "straddress") &_
"\n" & "City: " & Request( "city") &_
"\n" & "State: " & Request( "state") &_
"\n" & "Zip: " & Request( "zip")
Set NewMail = Server.CreateObject("CDONTS.NewMail")
NewMail.To = "martincc@cis.stvincent.edu"
NewMail.From = "martincc@cis.stvincent.edu"
NewMail.Subject = "Information Submitted"
NewMail.Body = Message
NewMail.Send
Set NewMail = Nothing //removes the object from memory
%>
<!-- retrieve and display textbox values -->
<p>Hi <% =Request( "fname" ) %>, </p><br />
<strong> Welcome! </strong> <br />
The information you submitted: <br />
First Name:
<% =Request( "fname" ) %>
<br />
Last Name:
<% =Request( "lname" ) %>
<br />
Street Address:
<% =Request( "straddress" ) %>
<br />
City:
<% =Request( "city" ) %>
<br />
State:
<% =Request( "state" ) %>
<br />
Zip:
<% =Request( "zip" ) %>
<br />
</body>
</html>
Within the body of the file, is a server-side script which concatenates all of the user
information from the form into a variable called "Message". Note that "Message" is
a string that is concatenated with the & symbol and that the code extends over several
lines, so the line continuation character _ is used.
The Request object recovers the information posted by the user to the textboxes
with the names used above as parameters to Request . Request returns the contents
of the textboxes indicated by the names.
The script then creates a mail file object on the server, assigns values to various
components of the mail file object and then calls the Send method to
send the information via email to the webmaster.
The final line in the script removes the mail file object from memory. The remainder of the file sends XHTML code to the client to indicate the information
that was submitted. Again, it uses the Request object to obtain the values of the
submitted information.
- Dietel, H. M., Dietel, P. J. & Neito, T. R. (2001) Internet & World Wide Web: How to Program. 2nd Edition. Prentice Hall, NJ.
|