ASP Basics
ASP is a server-side scripting technology developed
by Microsoft. It is an open, compile-free application
environment in which you can combine HTML, scripts,
and reusable components to build dynamic and powerful
Web applications.
An
ASP application consists of ASP pages published on a
Web site. ASP pages can contain HTML code, client-side
scripts, and server-side scripts. When a user requests
an ASP page, the Web server calls the ASP Server, which
processes the requested file from top to bottom, executing
any server-side scripts. It then formats a standard
Web page and sends the results to the user's browser.
Because
scripts can run on the server rather than on the client,
the Web server can do much of the work involved in generating
the HTML pages sent to browsers. Server-side scripts
cannot be readily copied because only the result of
the script is returned to the browser. Users cannot
view the script commands that created the page they
are viewing.
ASP
was designed as a faster and easier alternative to Common
Gateway Interface (CGI) scripting using Perl or C scripts.
ASP provides an easy-to-learn scripting interface (including
native support for both VBScript and JScript), along
with a number of predefined objects that simplify many
development tasks, such as maintaining user state and
defining global variables within an application. You
can also use Active-X Data Objects (ADO) components
to perform additional functions, including accessing
ODBC-compliant databases and outputting data to text
files.
You
can extend ASP scripts by using Java components and
extensible markup language (XML) .
ASP
runs as a service of the Web server, and is optimized
for multiple threads and multiple users. This means
that ASP is fast and easy to implement. ASP enables
you to separate the design of your Web page from the
details of programming access to databases and applications,
so programmers and Web designers can focus exclusively
on what they do best.
Following
are a few examples of what you can do with ASP applications.
You can:
·
Put your employee handbook online, and build an application
that allows employees to update their information.
·
Connect customer orders from an online storefront to
an existing inventory database and order-processing
system.
·
Give visitors a personalized view of information on
your Web site, flagging items that are new since their
last visit.
ASP Support?
1. We will provide support related to the server
maintenance and operation of the ASP server.
2. We will also assist users in finding
resources so that they can maximize the servers resources
as well as enjoy their web experience.
3. We do not provide debugging of ASP pages that
are placed on our servers. You should be an experienced
programmer before attempting to use ASP.
We have provided the following information as a courtesy.
Should you need further assistance ASP see our resources
below.
How to enable ASP on your account
Go to your control panel at http://yourdomain.com/menu
and click on the ASP icon. You will be taken to another
page which will give you the option to enable this service.
Wait 10-30 minutes and the server will activate this
feature. Enabling your site with ASP may require moving
your site to a different server, so please backup your
files and email before requesting ASP.
ASP
for the HTML Author
For the HTML author, ASP is an easy way to begin creating
Web applications. To process user input on the Web server
with Common Gateway Interface (CGI) applications, you
must learn a programming language such as Perl or C.
With ASP, however, you can collect HTML form information
and pass it to a database by using simple server-side
scripts written in VBScript or Jscript that are embedded
directly in your HTML documents. You can use server-side
ASP scripts to store HTML form information in a database,
personalize Web sites according to visitor preferences,
or use different HTML features based on the browser.
Creating an ASP Page
An Active Server Pages (ASP) file is a text file with
the extension .asp that contains any combination of
the following:
Text
HTML tags
Server-side scripts
A quick way to create an .asp file is to rename your
HTML files by replacing the existing .htm or .html file
name extension with an .asp extension. If your file
does not contain any ASP functionality, then the server
dispenses with the ASP script processing and efficiently
sends the file to the client. As a Web developer, this
affords you tremendous flexibility because you can assign
your files .asp extensions, even if you do not plan
on adding ASP functionality until later.
To
publish an .asp file on the Web, save the new file in
a virtual directory on your Web site (be sure that the
directory has Script or Execute permission enabled).
Next, request the file with your browser by typing in
the file's URL. (Remember, ASP pages must be served,
so you cannot request an .asp file by typing in its
physical path.) After the file loads in your browser,
you will notice that the server has returned an HTML
page. This may seem strange at first, but remember that
the server parses and executes all ASP server-side scripts
prior to sending the file. The user will always receive
standard HTML.
You
can use any text editor to create Asp files. As you
progress, you may find it more productive to use an
editor with enhanced support for ASP, such as Microsoft®
Visual InterDev. (For more information, visit
the Microsoft Visual InterDev Web site at http://msdn.microsoft.com/vinterdev/.)
Adding
Server-Side Script Commands
A server-side script is a series of instructions used
to sequentially issue commands to the Web server. (If
you have developed Web sites previously, then you are
probably familiar with client-side scripts, which run
on the Web browser.) In Asp files, scripts are differentiated
from text and HTML by delimiters. A delimiter is a character
or sequence of characters that marks the beginning or
end of a unit. In the case of HTML, these delimiters
are the less than (<) and greater than (>) symbols,
which enclose HTML tags.
ASP
uses the delimiters <% and %> to enclose script
commands. Within the delimiters, you can include any
command that is valid for the scripting language you
are using. The following example shows a simple HTML
page that contains a script command:
<HTML>
<BODY>
This page was last refreshed on <%= Now() %>.
</BODY>
</HTML>The VBScript function Now() returns the
current date and time. When the Web server processes
this page, it replaces <%= Now() %> with the current
date and time and returns the page to the browser with
the following result:
This
page was last refreshed on 01/29/99 2:20:00 PM.Commands
enclosed by delimiters are called primary script commands,
which are processed using the primary scripting language.
Any command that you use within script delimiters must
be valid for the primary scripting language. By default,
the primary scripting language is VBScript, but you
can also set a different default language. See Working
with Scripting Languages.
If
you are already familiar with client-side scripting,
you are aware that the HTML <SCRIPT> tag is used
to enclose script commands and expressions. You can
also use the <SCRIPT> tag for server-side scripting,
whenever you need to define procedures in multiple languages
within an Asp file. For more information, see Working
with Scripting Languages.
Mixing
HTML and Script Commands
You can include, within ASP delimiters, any statement,
expression, procedure, or operator that is valid for
your primary scripting language. A statement, in VBScript
and other scripting languages, is a syntactically complete
unit that expresses one kind of action, declaration,
or definition. The conditional If...Then...Else statement
that appears below is a common VBScript statement:
<%
Dim dtmHour
dtmHour = Hour(Now())
If dtmHour < 12 Then
strGreeting = "Good Morning!"
Else
strGreeting = "Hello!"
End If
%>
<%=
strGreeting %>Depending on the hour, this script
assigns either the value "Good Morning!" or
the value "Hello!" to the string variable
strGreeting. The <%= strGreeting %> statement
sends the current value of the variable to the browser.
Thus,
a user viewing this script before 12:00 noon (in the
Web servers time zone) would see this line of
text:
Good
Morning!A user viewing the script at or after 12:00
noon would see this line of text:
Hello!You
can include HTML text between the sections of a statement.
For example, the following script, which mixes HTML
within an If...Then...Else statement, produces the same
result as the script in the previous example:
<%
Dim dtmHour
dtmHour = Hour(Now())
If dtmHour < 12 Then
%>
Good Morning!
<% Else %>
Hello!
<% End If %>If the condition is truethat
is, if the time is before noonthen the Web server
sends the HTML that follows the condition (Good
Morning) to the browser; otherwise, it sends the
HTML that follows Else (Hello!) to the browser.
This way of mixing HTML and script commands is convenient
for wrapping the If...Then...Else statement around several
lines of HTML text. The previous example is more useful
if you want to display a greeting in several places
on your Web page. You can set the value of the variable
once and then display it repeatedly.
Rather
than interspersing HTML text with script commands, you
can return HTML text to the browser from within a script
command. To return text to the browser, use the ASP
built-in object Response. The following example produces
the same result as the previous scripts:
<%
Dim dtmHour
dtmHour = Hour(Now())
If dtmHour < 12 Then
Response.Write "Good Morning!"
Else
Response.Write "Hello!"
End If
%>
Response.Write sends the text that follows it to the
browser. Use Response.Write from within a statement
when you want to dynamically construct the text returned
to the browser. For example, you might want to build
a string that contains the values of several variables.
You will learn more about the Response object, and objects
in general, in Using Components and Objects and Sending
Content to the Browser. For now, simply note that you
have several ways to insert script commands into an
HTML page.
You
can include procedures written in your default primary
scripting language within ASP delimiters. Refer to Working
with Scripting Languages for more information.
If
you are working with JScript commands, you can insert
the curly braces, which indicate a block of statements,
directly into your ASP commands, even if they are interspersed
with HTML tags and text. For example:
<%
if (screenresolution == "low")
{
%>
This is the text version of a page.
<%
}
else
{
%>
This is the multimedia version of a page.
<%
}
%>--Or--
<%
if (screenresolution == "low")
{
Response.Write("This is the text version of a page.")
}
else
{
Response.Write("This is the multimedia version
of a page.")
}
%>Using ASP Directives
ASP provides directives that are not part of the scripting
language you use: the output directive and the processing
directive.
The
ASP output directive <%= expression %> displays
the value of an expression. This output directive is
equivalent to using Response.Write to display information.
For example, the output expression <%= city %>
displays the word Baltimore (the current value of the
variable) on the browser.
The
ASP processing directive <%@ keyword %> gives
ASP the information it needs to process an Asp file.
For example, the following directive sets VBScript as
the primary scripting language for the page:
<%@
LANGUAGE=VBScript %>The processing directive must
appear on the first line of an Asp file. To add more
than one directive to a page, the directive must be
within the same delimiter. Do not put the processing
directive in a file included with the #include statement.
(For more information, see Including Files.) You must
use a space between the at sign (@) and the keyword.
The processing directive has the following keywords:
The
LANGUAGE keyword sets the scripting language for the
Asp file. See Working with Scripting Languages.
The ENABLESESSIONSTATE keyword specifies whether an
Asp file uses session state. See Managing Sessions.
The CODEPAGE keyword sets the code page (the character
encoding) for the Asp file.
The LCID keyword sets the locale identifier for the
file.
The TRANSACTION keyword specifies that the Asp file
will run under a transaction context. See Understanding
Transactions.
Important You can include more than one keyword in a
single directive. Keyword/value pairs must be separated
by a space. Do not put spaces around the equal sign
(=).
The
following example sets both the scripting language and
the code page:
<%@
LANGUAGE="JScript" CODEPAGE="932"
%>White Space in Scripts
If your primary scripting language is either VBScript
or JScript, ASP removes white space from commands. For
all other scripting languages, ASP preserves white space
so that languages dependent upon position or indentation
are correctly interpreted. White space includes spaces,
tabs, returns, and line feeds.
For
VBScript and JScript, you can use white space after
the opening delimiter and before the closing delimiter
to make commands easier to read. All of the following
statements are valid:
<%
Color = "Green" %>
<%Color="Green"%>
<%
Color = "Green"
%>ASP removes white space between the closing delimiter
of a statement and the opening delimiter of the following
statement. However, it is good practice to use spaces
to improve readability. If you need to preserve the
white space between two statements, such as when you
are displaying the values of variables in a sentence,
use an HTML nonbreaking space character ( ).
For example:
<%
'Define two variables with string values.
strFirstName = "Jeff"
strLastName = "Smith"
%>
<P>This
Web page is customized for "<%= strFirstName
%> <%= strLastName %>." </P>
Exporting an Access Database into MySQL
1. First you must successfully install MySQL on your
Virtual Server. Be aware that you will need to consult
the MySQL users manual for information on using MySQL.
2. Add a user with password privileges if you like to
your MySQL database. Instructions on this are contained
in the Adding new user privileges section of the MySQL
users manual.
3. Download and install the necessary ODBC MySQL driver
on your computer. There are currently drivers available
for both Window95 and Windows NT. Select the appropriate
driver for your computer. Please visit the following
URL to download ODBC driver for your computer :
http://www.mysql.com/downloads/api-myodbc.html
4. Unzip the appropriate driver on your computer, likely
in a temp directory or other location of your choosing.
5. Run the setup program for the driver. To do this
simply double-click on the setup.exe in the directory
you unzipped the driver in.
6. Following the setup of the MySQL driver on your computer
you will need to configure it for use. To do this go
to your Control Panel (start -> setttings -> control
panel) and double click on ODBC icon. You will then
need to select whether you want to configure the ODBC
driver for use by a single user or for use by every
user on the computer. The first tab, "User DSN" is for
only a specific user and can only be used on your specific
computer. The second tab, "System DSN" is used to configure
the ODBC driver for all users on your computer. Depending
on which you choose to use, you will then click the
add button on the right side. By clicking the add button
you will be given a choice of drivers you can set up
for a data source. You should find MySQL in the list.
Select MySQL and click finish.
7. The TcX mysql driver default configuration screen
will then appear. You will want to fill out the fields
with the appropriate information.
a. Windows DNS Name: type a name for this particular
driver that you will be using for MySQL. The name is
something of your choosing. (example: everyoneMySQL)
b. Server: This is the name of the Virtual Server you
will be publishing your database to. (example: myserver.net)
c. MySQL Database Name: This needs to be the MySQL user
you created in step #2 in this list. (example: mysql)
d. Password: Simply the password, if applicable for
the MySQL user in the field above.
e. Port (if not 3306): If you are behind a Firewall
you will need to open up port 3306 or another port you
specify or it will not work correctly.
8. Now you are ready for using Access. Open up Access
and create or select the database you want to move to
your Virtual Server in the Tables section. Once you
have selected the appropriate table, select Save As/Export
under File. This will allow you to select the "To an
External File or Database" option. Click OK.
9. The Save Table screen will appear. You will want
to select the field and then change the "Save as type"
to ODBC Databases and click Export.
10. The Export screen appears. The "Export Addresses
to:" should simply be the name you want to call this
specific database table on the Virtual Server.
11. The "Select Data Source" screen should then appear.
Select the "Machine Data Source" tab and then select
the Data Source Name you should have set up previously
in step 7a.
12. The table should then be moved to the Virtual Server
under the user you specified for MySQL. To verify this,
use Telnet or SSH to connect to your Virtual Server
and find the table.
How To Connect To Your MS Access Database Using
ASP
MS-Access database cannot be put directly on our servers
as we run Linux based servers. But, SunOne ASP has provided
a tool enableing you to remotely access your database,
and still use all the functionality of ASP. First, you
will need to install the Sequelink utility on your local
system.
NOTE: Please note that Sequelink only works if
you are running Window NT or Windows 2000 on your PC.
1. Download Sequelink Utility and follow the steps for installation.
2. You need to provide us a static IP address that is
provided by your ISP for the system on which sequelink
and access database is setup. Your will need to submit
a support request at our Help Desk and
give us this information and we will enable the ODBC
connection to your ACCESS database on your account.
To use a MySQL database residing on the Linux server,
you need to use the following code for connection (you
may use this code for connecting to a MySQL database):
ConnString = "Driver={MySQL}; SERVER=localhost; "
ConnString = ConnString & "DATABASE=DatabaseName;
"
ConnString = ConnString & "UID=Username; "
ConnString = ConnString & "PASSWORD=Password"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnString
You need to modify the driver that you wish to use.
How do I connect to MySQL databases through ASP?
Click here for more
information on MySQL connections with ASP.
ASP
Resources
Sun Knowledgebase
Articles
A starting point for general questions or troubleshooting. |
ASP
Samples
Samples provided by Sun include Calendar, calculator,
etc... |
ASP
Developers Network:
Good basic information site. |
ASP
Advice:
Good site with lots of basic answers and tutorials. |
ASP
Toolbox:
Large collection of ASP resources, including reviews
and ratings of over 400 books. |
ASP-Zone:
Part of Fawcette Technical Publications' Dev-X site,
ASP-Zone offers a wide range of articles and how-to's,
plus FAQs. Some material requires registration,
and some requires paid subscription. |
LearnASP.com:
One of the original ASP sites, there is a great
deal of content here, plus links to a wide variety
of resources. |
The
ASP Resource Index:
Many links to many ASP resources. |
D
e v G u r u:
Multi-subject site, featuring exhaustive Object
reference |
ASP
Wire:
The folks at ASPXtras bring you this site that has
all of the latest press and product releases in
the ASP community. |
4GuysFromRolla:
Excellent site. Many resources, and a great series
of FAQs. |
ASPXtras:
ASP components and tools for sale. |
PowerASP:
Good site with code snippets and tutorials. |
ASPZone:
ASPZone is a smallish site that has a few articles
and a discussion forum. |
Active
Server Corner:
Good site with oft-updated content, including code
samples. |
ASPFree:
Includes free sample code and several demos. |
Action Jackson:
Large database of articles, plus voluminous forum. |
Microsoft Highlights for
ASP:
Some articles and links from Microsoft. |
Active
Server Pages Resources:
Companion site to the Active Server Pages Unleashed
book. |
ASP
Today:
Wrox Press' entry in the ASP Site race, this site
features daily articles including a searchable archive. |
15Seconds.com:
Another of the originals, 15Seconds is now part
of the Internet.com network of sites. 15Seconds
has a huge number of links and resources. They also
run the most active ASP Listserver. |
Programmer's Resource:
New site with some good ASP information. |
ASP
101:
Good site that offers a few original articles, code
samples, and an excellent array of links. |
ASP
SuperExpert:
Lots of information, very usefully categorized.
Great resource. |
Humble ASP FAQ:
A venerable, yet up-to-date FAQ. Lots of information. |