Вы находитесь на странице: 1из 10

ACTIVE SERVER PAGE

Introduction:

Active Server Pages (ASP) is one of the most exciting and interesting Internet
technologies ever created by Microsoft. ASP is a program that runs inside IIS (Internet
Information Services). With ASP, developers can build dynamic websites very easily. A
script running on the server receives a request from the client and generates a customized
HTML page, which will be returned to the client. ASP is available with Microsoft IIS
(Internet Information Server). It is available only with the Windows NT operating system.
If you are using Windows 98 or 2000, you can use Microsoft Personal Web Server to test
your ASP scripts.
ASP is a feature of the Microsoft Internet Information Server (IIS), but, since the
server-side script is just building a regular HTML page, it can be delivered to almost any
browser. You can create an ASP file by including a script written in VBScript or JScript in
an HTML file or by using ActiveX Data Objects (ADOs) program statements in the
HTML file. You name the HTML file with the ".asp" file suffix. Microsoft recommends
the use of the server-side ASP rather than a client-side script, where there is actually a
choice, because the server-side script will result in an easily displayable HTML page.
Client-side scripts (for example, with JavaScript) may not work as intended on older
browsers.
When you type a URL in the Address box or click a link on a Web page, you're
asking a Web server on a computer somewhere to send a file to the Web browser
(sometimes called a "client") on your computer. If that file is a normal HTML file, it
looks exactly the same when your Web browser receives it as it did before the Web server
sent it. After receiving the file, your Web browser displays its contents as a combination
of text, images, and sounds. To sum up
• An ASP file is just the same as an HTML file
• An ASP file can contain text, HTML, XML, and scripts
• Scripts in an ASP file are executed on the server
• An ASP file has the file extension ".asp"
Definition:
Active Server Pages (ASPs) are Web pages that contain server-side scripts in
addition to the usual mixture of text and HTML (Hypertext Markup Language) tags.
Server-side scripts are special commands you put in Web pages that are processed before
the pages are sent from your Personal Web Server to the Web browser of someone who's
visiting your Web site.
An Active Server Page (ASP) is an HTML page that includes one or more scripts
(small embedded programs) that are processed on a Microsoft Web server before the page
is sent to the user. An ASP is somewhat similar to a server-side include or a common
gateway interface (CGI) application in that all involve programs that run on the server,
usually tailoring a page for the user.
ASP Compatibility:
• ASP is a Microsoft Technology
• To run IIS you must have Windows NT 4.0 or later
• To run PWS you must have Windows 95 or later
• ChiliASP is a technology that runs ASP without Windows OS
• InstantASP is another technology that runs ASP without Windows

The Differences between Active Server Pages and Conventional HTML

With conventional static HTML, the user types in a Web address and the browser
sends a request for the Web page to a Web server. The Web server receives the request
and retrieves the appropriate HTML file from a disk or memory and transmits it back to
the browser. The user's Web browser translates the HTML file and the results are
displayed in the browser window. The results are static as long as the underlying HTML
page is unchanged. Static Web pages are used when information is not expected to
change much over time. Static Web pages are ideal for home pages or sites where content
is not going to be modified frequently. In order to make changes to static Web pages, one
must edit the HTML file.

ASP and conventional HTML work in almost the same way. One major difference
between ASP and conventional HTML is that ASP is dynamic. This is because with ASP,
scripting code runs on the server and produces HTML output, which is then sent to the
browser for display.
When a browser requests an ASP file from the Web server, the ASP
interpreter reads through the ASP file, executes any of the ASP commands contained
within and sends the resulting HTML to the browser. This means that the same ASP page
might produce HTML that appears in the browser differently each time it is requested. An
ASP file can contain any combination of HTML and script. Since ASP pages produce
standard HTML, they require no specific browser. Finally
• When a browser requests an HTML file, the server returns the file
• When a browser requests an ASP file, IIS passes the request to the ASP engine.
The ASP engine reads the ASP file, line by line, and executes the scripts in the
file. Finally, the ASP file is returned to the browser as plain HTML

Overall Working of an ASP Page:

1. Server receives the request for the ASP Page from the client
2. Server loads the ASP Page and executes the Script and HTML in the page.
3. A new HTML page is generated
4. It is then returned to the user and viewed in the browser.

Since pure HTML is generated, it obviously works on browsers such as Internet Explorer
and Netscape.

What ASP can do?


1. Displaying Alert message in a small window
2. Authenticating user before entering to members only area
3. Validating data entered by user in a text box ( or form )
Applications of ASP:
There are many things you can do with Active Server Pages.
• Dynamically edit, change or add any content of a Web page
• Respond to user queries or data submitted from HTML forms
• Access any data or databases and return the results to a browser
• Customize a Web page to make it more useful for individual users
• The advantages of using ASP instead of CGI and Perl, are those of
simplicity and speed
• Provide security since your ASP code can not be viewed from the browser
• Clever ASP programming can minimize the network traffic
• You can display date, time, and other information in different ways.
• You can make a survey form and ask people who visit your site to fill it
out, send emails, save the information to a file, etc
Creating and Converting Active Server Pages:
An ASP files can be created using any text editor or Web development tool. Just
remember to convert your existing .html page to an .ASP page by changing the file
extension. This informs the server to process the page and produce the HTML output
proceeding sequentially through the file. Anything not delimited as script will be sent
directly to the output; any scripts will be executed and their results sent to the output.
Web Server Installation
Before being able to run ASP pages, you need to confirm that we have an ASP-
enabled Web server installed on your computer. If Windows NT or Personal Web Server
(PWS) for Windows 9x on your system have been installed in the system, we were most
likely asked if you wanted to install Internet Information Server (IIS). After installing IIS,
you should have installed ASP. To install ASP in Windows 9X.
1. Open the Add-ons folder on your Windows98 CD, find the PWS folder and run
the setup.exe file.
2. An Inetpub folder will be created on your harddrive. Open it and find the
wwwroot folder.
3. Create a new folder, like "MyWeb", under wwwroot.
4. Use a text editor to write some ASP code, save the file as "test1.asp" in the
"MyWeb" folder.
5. Make sure your Web server is running - The installation program has added a new
icon on your task bar (this is the PWS symbol). Click on the icon and press the
Start button in the window that appears.
6. Open your browser and type in "http://localhost/MyWeb/test1.asp", to view your
first ASP page.
Internet Information Server (IIS)
The foundation of ASP is Microsoft's Internet Information Server. IIS utilizes
scripting engines for VBScript and other languages. VBScript is the default language of
ASP; however you can use other scripting languages such as JavaScript or PerlScript. In
order to run your ASP page, you must place it in a directory that is accessible to the Web
server. This is because the server must first interpret the ASP file so that it can run
properly. If you simply try to open the ASP file in a browser, it will not work.
The ASP file itself contains VBScript that we do not want to send to the browser.
However, we do want to send the output of the interpreted ASP file to the browser. IIS's
default root of the web directory for Windows NT and Windows 9x is
C:InetPubwwwroot. The directory that we will be using as the home for the web pages
we create is InetPub. Files in this directory are accessed through your browser using the
URL http://localhost/page.asp, where page.asp is the ASP file you wish to view. If you
wish to place your ASP page in a folder other than the default home directory, you will
need to tell the Web server where your chosen folder is by designating it as a virtual web
directory. To install IIS and run ASP on Windows 2000
1. From your Start Button, go to Settings, and Control Panel
2. In the Control Panel window select Add/Remove Programs
3. In the Add/Remove window select Add/Remove Windows Components
4. In the Wizard window check Internet Information Services, click OK
5. An Inetpub folder will be created on your harddrive
6. Open the Inetpub folder, and find a folder named wwwroot
7. Create a new folder, like "MyWeb", under wwwroot.
8. Use a text editor to write some ASP code, save the file as "test1.asp" in the
"MyWeb" folder
9. Make sure your Web server is running - The installation program has added a new
icon on your task bar (this is the IIS symbol). Click on the icon and press the Start
button in the window that appears.
10. Open your browser and type in "http://localhost/MyWeb/test1.asp", to view your
first ASP page
Writing an ASP Page:
The script in an ASP page can be written by using Visual Basic Script, JavaScript,
or JScript (or ECMAScript). JScript is the Microsoft Version of JavaScript. You should
use Notepad or any other text editor to write your code. The most ideal tool for coding
ASP is Microsoft Visual Interdev. After typing your code, you should save the file with
the extension .asp if you use Notepad. If you are using Microsoft Visual Interdev, your
.asp file is automatically saved as a .asp file. (See the end of this Session for more
information about this tool.)
Basic Syntax Rule
An ASP file normally contains HTML tags, just like an HTML file. However, an
ASP file can also contain server scripts, surrounded by the delimiters <% and %>.
Server scripts are executed on the server, and can contain any expressions, statements,
procedures, or operators valid for the scripting language you prefer to use. For example,
consider the following script:
<% =total%>
The value of the variable total will be displayed as output.
Basic ASP Programming:
a) Displaying the Current Date and Time
To display the current date by itself in a Web page, type:
<% =date %>
When you view the page in your browser, you should see something like this:
Thu, Jan 23, 1997
To display the current time by it, type:
<% =time %>
When you view the page, you should see something like this:
4:19:46 PM
b) Displaying Hello World
<html>
<head>
<title>Hello World</title>
<% = "HelloWorld"%>
</head>
<body>
</body>
</html>
ASP code with Variable Declaration:
Example 1:
<html>
Header 1
<body>
<% Header 2
dim i
for i=1 to 6 Header 3
response.write("<h" & i & ">Header " & i & "</h" & i & ">")
next
%> Header 4
</body>
</html> Header 5
Example 2:

<html>
<body> My name is: Donald Duck
<%
dim name
name="Donald Duck"
response.write("My name is: " & name)
%>
</body>
</html>

ASP with Control Statement:


<html>
<body>
<%
dim h
h=hour(now())
response.write("<p>" & now())
response.write(" (Norwegian Time) </p>")
If h<12 then
response.write("Good Morning!")
else
response.write("Good day!")
end if
%>
</body>
</html>

ASP Procedures :
The ASP source code can contain procedures and functions:
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
</body>
</html>
To save the file:
Save the file as Example 1.1 in the <a href="file:///C:/Inetpub/wwwroot">
C:Inetpubwwwroot</a> directory.
You should save all your ASP files in this directory so that the server can be able
to locate the files and execute them.
Running an ASP Page:
Now, it's time to fire up your Web browser to view the output. Open your browser
and type
<a href="http://localhost/Example1.1.asp">http://localhost/Example1.1.asp</a>
in the address bar
ASP Objects:
Active Server Pages consist of six built in objects. They are ready made objects which
provide functionality to your web pages without requiring you to make custom objects.
Following are the six built in ASP objects:
• Application
• ASPError
• ObjectContext
• Request & Response
• Server
• Session
Application Object:
The Application object is created when the first .asp page is requested after
starting the IIS and remains there until the server shuts down. All the variables created
with application object have application level scope meaning there by that they are
accessible to all the users.
Error Object:
The ASPError object is created when Server.GetLastError is called. It contains a
lot of info about the last scripting error found in the page.
Object Context:
The ObjectContext object is used to commit or abort transactions.
Request Object:
The Request object makes available all the values that client browser passes to the
server during an HTTP request. It includes client browser info, cookie details ( of this
domain only ), client certificates ( if accessing through SSL ) etc.
Response Object:
The Response object is used to send the output back to the client (browser). It
includes all the HTTP variables, cookies that will be stored on the client browser and
other info about the content being sent.
Server Object
The Server object makes us available the methods and properties of our server ( IIS ).
Session Object
The Session object is automatically created every time client browser access
pages from your web site. Session object is specific for every user and varies from user to
user. It can be used to store variables specific for a user and IIS will maintain these
variables when the client moves across pages within your site.
Advantages & Disadvantages of ASP:
ASP is a server side script and it can perform many backend processing jobs for a
web site, same way it can't do many things particularly the client end operations as it has
no control over the client end events or user controls. So there are many advantages and
disadvantages of using ASP to manage web pages.
Using server side scripting language like ASP we can manage the content of any
page and such dynamic code (or content) for the web browsers can be generated based on
various conditions we set in our ASP program. To a visitor the back end script or
processing is of no use. They are more interested in design, content, speed etc. So there is
no point in asking ASP engine to work when there is simple html content to be displayed
at browser end. This will also improve the loading speed of the page. The user browser
does not understand scripts we run at server. Brower understands JavaScript (if enabled),
html, CSS etc. So what ever output we want to be send to the browser has to be written
using these languages. So the task we want to be performed at client end can't be written
at server end using ASP.
ASP engine finishes its job of processing the code and then send the codes to
users browser. From this point on words till again the page request comes back to server,
there is no control of ASP on the page. So we should not expect ASP to perform some
tasks which are likely to happen at the client browser end. This will be clear when we
discuss some of the task and where ( client or server side ) the task is to be completed and
which script will take care of it.
References:
1. http://www.plus2net.com/asp-tutorial/ASP_Introduction.php
2. http://www.w3schools.com/asp/asp_install.asp
3. http://www.asptutorial.info/
4. www.asp101.com/
5. http://www.stardeveloper.com/articles/display.html?article=2000030902&page=2

Вам также может понравиться