Sie sind auf Seite 1von 22

ASP Beginning

<html>
<body>
<%
response.write("My first ASP script!")
%>
</body>
</html>
What you shouId aIready know
Before we continue with ASP we shouId have some basic
understanding of the foIIowing:
W HTML / XHTML
W A scripting Ianguage Iike JavaScript or VBScript
An ASP fiIe can contain text, HTML tags and scripts. Scripts in an ASP
fiIe are executed on the server.
What is ASP ?
W ASP s t ands f or Ac t i ve Ser ver Pages
W ASP i s a Mi c r os of t Tec hnol ogy
W ASP i s a pr ogr am t hat r uns i ns i de S
W S s t ands f or nt er net nf or mat i on Ser vi c es
W S c omes as a f r ee c omponent wi t h Wi ndows 2000
W S i s al s o a par t of t he Wi ndows NT 4. 0 Opt i on Pac k
W The Opt i on Pac k c an be downl oaded f r om Mi c r os of t
W PWS i s a s mal l er - but f ul l y f unc t i onal - ver s i on of S
W PWS c an be f ound on your Wi ndows 95/ 98 CD
ASP Compat i bi I i t y
WTo run S you must have Windows NT 4.0 or later
W To run PWS you must have Windows 95 or later
W ChiliASP is a technology that runs ASP without Windows OS
W nstantASP is another technology that runs ASP without Windows
What is an ASP FiIe?
W An ASP file is just the same as an HTML file
W An ASP file can contain text, HTML, XML, and scripts
W Scripts in an ASP file are executed on the server
W An ASP file has the file extension ".asp"
How Does ASP Differ from HTML?
W When a browser requests an HTML file, the server returns the file
W When a browser requests an ASP file, S 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
What can ASP do for you?
W Dynamically edit, change, or add any content of a Web page
W #espond to user queries or data submitted from HTML forms
W Access any data or databases and return the results to a browser
W Customize a Web page to make it more useful for individual users
W The advantages of using ASP instead of CG and Perl, are those of simplicity and speed
W Provide security - since ASP code cannot be viewed from the browser
W Clever ASP programming can minimize the network traffic
ou can run ASP on your own PC.
Your Windows PC as a Web Server
W our own PC can act as a web server if you install S or PWS
W S or PWS turns your computer into a web server
W Microsoft S and PWS are free web server components
IIS - Internet Information Server
W S is a set of nternet-based services for servers created by Microsoft for use
with Microsoft Windows.
W S comes with Windows 2000, XP, Vista, and Windows 7. t is also available for
Windows NT.
W S is easy to install and ideal for developing and testing web applications.
PWS - Personal Web Server
W PWS is for older Windows system like Windows 95, 98, and NT.
W PWS is easy to install and can be used for developing and testing web applications including
ASP.
W We don't recommend running PWS for anything else than training. t is outdated and has
security issues.
Windows Web Server Versions
W Windows 7 (all editions) come with S 7.5
W Windows Vista Business, Enterprise and Ultimate come with S 7
W Windows Vista Home Premium comes with S 7
W Windows Vista Home Edition does not support PWS or S
W Windows XP Professional comes with S 5.1
W Windows XP Home Edition does not support S or PWS
W Windows 2000 Professional comes with S 5.0
W Windows NT Professional comes with S 3 and also supports S 4
W Windows NT Workstation supports PWS and S 3
W Windows ME does not support PWS or S
W Windows 98 comes with PWS
W Windows 95 supports PWS
W How to nstall S on Windows 7 and Windows Vista
Steps to instaII IIS:
W Open the Control Panel from the Start menu
W Double-click Programs and Features
W Click "Turn Windows features on or off" (a link to the left)
W Select the check box for nternet nformation Services (S), and click OK
W After you have installed S, make sure you install all patches for bugs and security problems.
(#un Windows Update).
How to InstaII IIS on Windows XP and Windows 2000
WFollow these steps to install S:
W On the Start menu, click Settings and select Control Panel
W Double-click Add or #emove Programs
W Click Add/#emove Windows Components
W Click nternet nformation Services (S)
W Click Details
W Select the check box for World Wide Web Service, and click OK
W n Windows Component selection, click Next to install S
W After you have installed S, make sure you install all patches for bugs and security problems. (
#un Windows Update).
After you have instaIIed IIS or PWS foIIow these steps:
W Look for a new folder called netpub on your hard drive
W Open the netpub folder, and find a folder named wwwroot
W Create a new folder, like "MyWeb", under wwwroot
W Write some ASP code and save the file as "test1.asp" in the new folder
W Make sure your Web server is running (see below)
W Open your browser and type "http://localhost/MyWeb/test1.asp", to view your first web page
How to instaII PWS on Windows 95, 98, and Windows NT
For Windows 98: Open the Add-ons folder on your Windows CD, find the PWS folder and
run setup.exe to install PWS.
For Windows 95 or Windows NT: Download "Windows NT 4.0 Option Pack" from
Microsoft, and install PWS.
How to install S on Windows Server 2003
1. When you start the Windows Server 2003, you should see the Manage our Server wizard
2. f the wizard is not displayed, go to Administrative Tools, and select Manage our Server
3. n the wizard, click Add or #emove a #ole, click Next
4. Select Custom Configuration, click Next
5. Select Application Server role, click Next
6. Select Enable ASP.NET, click Next
7. Now, the wizard may ask for the Server 2003 CD. nsert the CD and let it run until it is finished,
then click the Finish button
8. The wizard should now show the Application Server role installed
1. Click on Manage This Application Server to bring up the Application Server
Management Console (MMC)
2. Expand the nternet nformation Services (S) Manager, then expand your
server, and then the Web Sites folder
3. ou should see the Default Web Site, and it should not say (Stopped)
4. S is running!
5. n the nternet nformation Services (S) Manager click on the Web Service
Extensions folder
6. Here you will see that Active Server Pages are Prohibited (this is the default
configuration of S 6)
7. Highlight Active Server Pages and click the Allow button
8. ASP is now active!
Write Output to a Browser
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.
The response.write Command
The response.write command is used to write output to a browser. The following example sends
the text "Hello World" to the browser:
Example
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
There is also a shorthand method for the response.write command.
The following example also sends the text "Hello World" to the
browser:
xampIe :
<htmI>
<body>
<%
="HeIIo WorId!"
%>
</body>
</htmI>
&sing VBScript in ASP
ou can use several scripting languages in ASP. However, the default
scripting language is VBScript:
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
The example above writes "Hello World!" into the body of the document.
Using JavaScript in ASP
To set JavaScript as the default scripting language for a particular page
you must insert a language specification at the top of the page:
<%@ language="javascript"%>
<html>
<body>
<%
#esponse.Write("Hello World!")
%>
</body>
</html>
Lifetime of VariabIes
A variable declared outside a procedure can be accessed and changed by any script in the ASP
file.
A variable declared inside a procedure is created and destroyed every time the procedure is
executed. No scripts outside the procedure can access or change the variable.
To declare variables accessible to more than one ASP file, declare them as session variables or
application variables.
Session VariabIes
Session variables are used to store information about ONE single user, and are available to all
pages in one application. Typically information stored in session variables are name, id, and
preferences.
AppIication VariabIes
Application variables are also available to all pages in one application. Application variables are
used to store information about ALL users in one specific application.
In ASP you can caII a JavaScript procedure from a VBScript and vice
versa.
Procedures
The ASP source code can contain procedures and functions:
Example
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>#esult: <%call vbproc(3,4)%></p>
</body>
</html>
nsert the <%@ Ianguage="Ianguage" %> Iine above the <htmI> tag to write the
procedure/function in another scripting Ianguage:
Example
<%@ language="javascript" %>
<html>
<head>
<%
function jsproc(num1,num2)
{
#esponse.Write(num1*num2)
}
%>
</head>
<body>
<p>#esult: <%jsproc(3,4)%></p>
</body>
</html>
Differences Between VBScript and JavaScript
When calling a VBScript or a JavaScript procedure from an ASP file written
in VBScript, you can use the "call" keyword followed by the procedure name.
f a procedure requires parameters, the parameter list must be enclosed in
parentheses when using the "call" keyword. f you omit the "call" keyword,
the parameter list must not be enclosed in parentheses. f the procedure has
no parameters, the parentheses are optional.
When calling a JavaScript or a VBScript procedure from an ASP file written
in JavaScript, always use parentheses after the procedure name.

Das könnte Ihnen auch gefallen