Download presentation
Presentation is loading. Please wait.
1
ASP
2
Active Server Pages Microsoft Technology
use to create and run dynamic, interactive Web server applications ASP is a program that runs inside IIS(Internet Information Service) PWS (Personal Web Server) is a smaller - but fully functional - version of IIS When a browser requests an ASP file, IIS passes the request to the ASP engine.
4
What is an ASP File? 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"
5
What you can do with ASP? 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
6
The Basic Syntax Rule An ASP file normally contains HTML tags, just like an HTML file. an ASP file can also contain server scripts, surrounded by the delimiters <% and %>. Server scripts are executed on the server, and can contain expressions, statements, Procedures or operators valid for the scripting language you prefer to use. the default scripting language is VBScript
7
Write Output to a Browser
The response.write command is used to write output to a browser. Example <html> <body> <% response.write("Hello World!") %> // <%="Hello World!"%> </body> </html>
8
ASP Variables <%@ Language="Vbscript" %>
<% Option Explicit %> VbScript is used, this is how you declare variable DIM varaibleName or Const variableName. <html> <body> <% dim h h="Hello World" response.write("Say: " & h) %> </body> </html>
9
Variable Example <% Dim name, email, age name=”John M”
age=35 response.write(“Your Name: “ & name & "<br>") response.write(“Your “ & & "<br">) response.Write(“Your age: “ & age) %>
10
ASP Arrays <% %> Dim Cars(3) cars(0)="Jeep Grand Cherokee"
cars(1)="Jeep Wrangler" cars(2)="Jeep Liberty" cars(3)="Jeep Cherokee Briarwood" response.write(cars(0) & "<br>") response.write(cars(1) & "<br>") response.write(cars(2) & "<br>") response.write(cars(3) & "<br>") %>
11
Sub Procedures Function Procedures If Then—Else--End if Case Statement
Loop Statements For…Loop – step counter Do…Loop (Until,While) While..Wend
12
#include Directive insert the content of one ASP file into another ASP file before the server executes it used to create functions, headers, footers, or elements that will be reused on multiple pages. <!--#include file ="somefilename"-->
13
ASP Objects
14
Request: To get information from the user
Response: To send information to the user Server: To control the Internet Information Server Session: To store information about and change settings for the user's current Web-server session Application: To share application-level information and control settings for the lifetime of the application
15
Objects contains collections (bits of information that are accessed in the same way).
Objects use methods to do some type of Procedure Properties to store any of the object's attributes Events
16
The Request object The Request object retrieves the values that the client browser passed to the server during an HTTP request. Syntax Request[.collection|property|method](variable)
17
Collections ClientCertificate Cookies Form QueryString ServerVariables Properties TotalBytes - total number of bytes the client is sending in the body of the request. Method BinaryRead
18
All variables can be accessed directly by calling Request(variable) without the collection name. In this case, the Web server searches the collections in the following order. QueryString Form Cookies ClientCertificate ServerVariables
19
Request.Form (“FirstName”)
Request.QueryString (“FirstName”)
20
The Response object The Response object is used to send information to the user. Syntax Response.collection|property|method Collection Cookies- Specifies cookie values
21
Properties Buffer - Indicates whether page output is buffered. CacheControl - Determines whether proxy servers are able to cache the output generated by ASP. Charset - Appends the name of the character set to the content-type header. ContentType - Specifies the HTTP content type for the response. Expires- Specifies the length of time before a page cached on a browser expires. ExpiresAbsolute - Specifies the date and time on which a page cached on a browser expires.
22
Methods AddHeader Sets the HTML header name to value. AppendToLog Adds a string to the end of the Web server log entry for this request. BinaryWrite Writes the given information to the current HTTP output without any character-set conversion. Clear Erases any buffered HTML output. End Stops processing the .asp file and returns the current result. Flush Sends buffered output immediately. Redirect Sends a redirect message to the browser, causing it to attempt to connect to a different URL. Write Writes a variable to the current HTTP output as a string. This can be done by using the construct
23
<% dim numvisits response. cookies("NumVisits")
<% dim numvisits response.cookies("NumVisits").Expires=date+365 numvisits=request.cookies("NumVisits") if numvisits="" then response.cookies("NumVisits")=1 response.write("Welcome! This is the first time you are visiting this Web page.") else response.cookies("NumVisits")=numvisits+1 response.write("You have visited this ") response.write("Web page " & numvisits) if numvisits=1 then response.write " time before!" else response.write " times before!" end if end if %>
24
Server.property|method
Server object provides access to methods and properties on the server. Server.property|method Properties ScriptTimeout Methods CreateObject HTMLEncode Applies HTML encoding to the specified string. MapPath Maps the specified virtual path, either the absolute path on the current server or the path relative to the current page, into a physical path. URLEncode Applies URL encoding rules, including escape characters, to the string.
25
<% Dim DB Set DB = Server.CreateObject (“ADODB.Connection”) DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + “C:\Databases\Students.mdb”) Dim RS Set RS = Server.CreateObject (“ADODB.Recordset”) RS.Open “SELECT * FROM Students”, DB If RS.EOF And RS.BOF Then Response.Write “There are 0 records.” Else RS.MoveFirst While Not RS.EOF Response.Write RS.Fields (“FirstName”) Response.Write RS.Fields (“LastName”) Response.Write “<HR>” RS.MoveNext Wend End If %>
26
Session object Session.collection|property|method Collections Contents
StaticObjects Properties CodePage - used for symbol mapping. LCID - locale identifier. SessionID Timeout
27
Methods Abandon This method destroys a Session object and releases its resources. Events Scripts for the following events are declared in the global.asa file. Session_OnEnd Session_OnStart
28
Application object store information that persists for the entire lifetime of an application Application.method Collections Contents - Contains all of the items of Application StaticObjects - objects added to the session with the <OBJECT> tag. Lock - prevents other clients from modifying Application object properties. Unlock - allows other clients to modify Application object
29
Events Application_OnEnd Application_OnStart
30
Global.asa Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application. Application events Session events <object> declarations TypeLibrary declarations the #include directive
31
RESTRICTIONS This file can't display information Use Server and Application objects in the Application_OnStart and Application_OnEnd subroutines. In the Session_OnEnd subroutine, can use Server, Application, and Session objects. In the Session_OnStart subroutine you can use any built-in object.
32
<script language="vbscript" runat="server"> sub Application_OnStart 'some code end sub sub Application_OnEnd 'some code end sub sub Session_OnStart 'some code end sub sub Session_OnEnd 'some code end sub </script>
33
<object> Declarations
It is possible to create objects with session or application scope in Global.asa by using the <object> tag. <object runat="server" scope="scope" id="id" {progid="progID"|classid="classID"}> .... </object> Parameter Description scope Sets the scope of the object (either Session or Application) id Specifies a unique id for the object ProgID An id associated with a class id. The format for ProgID is [Vendor.]Component[.Version] Either ProgID or ClassID must be specified. ClassID Specifies a unique id for a COM class object.
34
TypeLibrary Declarations
A TypeLibrary is a container for the contents of a DLL file corresponding to a COM object. the constants of the COM object can be accessed errors can be better reported by the ASP code. <!--METADATA TYPE="TypeLib" file="filename" uuid="id" version="number" lcid="localeid" -->
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.