Active Server Page(ASP)

26
Active Server Page (ASP) Presented By Keshab Nath

description

 

Transcript of Active Server Page(ASP)

Page 1: Active Server Page(ASP)

Active Server Page (ASP)

Presented By

Keshab Nath

Page 2: Active Server Page(ASP)

Introduction to ASP

• What is ASP?– ASP stands for Active Server Pages. – ASP is a program that runs inside IIS. – IIS stands for Internet Information Services. – ASP is Microsoft’s solution to building advanced Web sites.

Page 3: Active Server Page(ASP)

Processing of an HTML Page

RequestBrowser Web Server

Memory-HTML fileHTML File

When a browser requests an HTML file, the server returns the file

Page 4: Active Server Page(ASP)

Processing of an ASP Page

RequestBrowser Web Server

Memory-ASP FileHTML File Processing

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.

Page 5: Active Server Page(ASP)

Introduction to ASP

ASP page can consists of the following:

– HTML tags.– Scripting Language (JavaScript/VBScript).– ASP Built-In Objects.– ActiveX Components eg. : ADO – ActiveX Data

Objects.

So, ASP is a standard HTML file with extended additional features.

Page 6: Active Server Page(ASP)

ASP Syntax

– An ASP file normally contains HTML tags, just as a standard HTML file.

– In addition, an ASP file can contain server side scripts, surrounded by the delimiters <% and %>. Server side scripts are executed on the server, and can contain any expressions, statements, procedures, or operators that are valid for the scripting language you use.

– The response.write command is used to write output to a browser

Page 7: Active Server Page(ASP)

ASP Syntax

• Scripts– Script is nothing but a set of commands that are

written to perform a specific task

– These commands are VBScript or JavaScript commands

– There are two types of Scripts:• Client-Side Script : Runs On Browser (default : JavaScript)

• Server-Side Script : Runs On Server (default : VBScript)

– Scripts in an ASP file are executed on the server.

Page 8: Active Server Page(ASP)

ASP SyntaxScripts

– Client-Side Script is embedded into the HTML file using tags:<script language=“JavaScript/VbScript”>

{JavaScript/Vbscript Code}</script>

– Server-Side Script is embedded into the ASP file using tags:<script language=Vbscript/JavaScript RunAt=SERVER>

{Vbscript/JavaScript Code}

</Script>

OR

<%@ Language = “VBScript/JavaScript” %><% {VBScript/JavaScript Code} %>

Page 9: Active Server Page(ASP)

Example

<html><body><%response.write("Hello World!")

%></body></html>

Page 10: Active Server Page(ASP)

ASP Variables• Variables

– Variables are used to store information

– This example demonstrates how to create a variable, assign a value to it, and insert the variable value into a text.

<html><body><%

Dim namename=“Tripti Arora"Response.Write("My name is: " & name)

%></body></html>

Page 11: Active Server Page(ASP)

ASP Variables

• Arrays– Arrays are used to store a series of related data items.– This example demonstrates how you can make an array

that stores names.<%Dim name(5)name(0) = "Jan Egil"name(1) = "Tove"name(2) = "Hege"name(3) = "Stale"name(4) = "Kai Jim"name(5) = "Borge"For i = 0 to 5

Response.Write(name(i) & "<br />")Next%></body></html>

Page 12: Active Server Page(ASP)

Including Files

• The #include Directive– It is possible to insert the content of another file

into an ASP file before the server executes it, with the server side #include directive.

– The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages.

Page 13: Active Server Page(ASP)

Including Files• How to Use the #include Directive

– Here is a file called "mypage.asp": <html> <body> <h3>Words of Wisdom:</h3><p><!--#include file="wisdom.inc"--></p> <h3>The time is:</h3><p><!--#include file="time.inc"--></p></body> </html>

– Here is the "wisdom.inc" file:"One should never increase, beyond what is necessary,the number of entities required to explain anything."

– Here is the "time.inc" file: <%Response.Write(Time)%>

<!-- #include virtual="somefilename“ - ->Or<!--#include file ="somefilename"-->

Syntax

Page 14: Active Server Page(ASP)

Including Files

• Source code in a browser, it will look something like this:

<html><body><h3>Words of Wisdom:</h3><p>"One should never increase, beyond what is necessary, the number of entities required to explain anything."</p>

<h3>The time is:</h3><p>11:33:42 AM</p></body></html>

Page 15: Active Server Page(ASP)

ASP Forms and User Input

• User Input– To get information from forms, you can use the

Request Object– Example<form method="GET" action="tizagGet.asp"> FirstName <input type="text" name=“fname"/> LastName <input type="text" name=“lname"/> <input type="submit" /> </form>– There are two ways to get form information: The Request.QueryString command and the Request.Form command.

Page 16: Active Server Page(ASP)

• Request.QueryString

– This collection is used to retrieve the values of the variables in the HTTP query string.

– The form data we want resides within the Request Object's QueryString collection

– Information sent from a form with the GET method is visible to everybody (in the address field) and the GET method limits the amount of information to send.

– If a user typed “Bill" and "Gates" in the form example above, the url sent to the server would look like this: http://www.asp.com/pg.asp?fname=Bill&lname=Gates

Request Object - Collections

Page 17: Active Server Page(ASP)

Request Object - CollectionsRequest.QueryString

– The ASP file "pg.asp" contains the following script: <body>Welcome<%response.write(request.querystring("fname"))

response.write(request.querystring("lname"))%></body>

– The example above writes this into the body of a document:

Welcome Bill Gates

Page 18: Active Server Page(ASP)

Request Object - Collections

• Request.Form– It is used to retrieve the values of form elements

posted to the HTTP request body, using the POST method of the <Form> Tag.

– Information sent from a form with the POST method is invisible to others.

– The POST method has no limits, you can send a large amount of information.

– If a user typed "Bill" and "Gates" in the form example above, the url sent to the server would look like this:http://www.asp.com/pg.asp

Page 19: Active Server Page(ASP)

Request Object - Collections

• Request.Form– The ASP file "pg.asp" contains the following script:

<body>Welcome<%response.write(request.form("fname"))response.write("&nbsp;")response.write(request.form("lname"))%></body>

– The example above writes this into the body of a document:

Welcome Bill Gates

Page 20: Active Server Page(ASP)

ASP Session

• The Session Object– The Session object is used to store information

about each user entering the Web-Site and are available to all pages in one application.

– Common information stored in session variables are user’s name, id, and preferences.

– The server creates a new Session object for each new user, and destroys the Session object when the session expires or is abandoned or the user logs out.

Page 21: Active Server Page(ASP)

ASP Session• Store and Retrieve Variable Values

– The most important thing about the Session object is that you can store variables in it, like this:

<% Session("TimeVisited") = Time() Response.Write("You visited this site at:

"&Session("TimeVisited")) %> Here we are creating two things actually: a key and a value. Above

we created the key "TimeVisited" which we assigned the value returned by the Time() function.

Display:You visited this site at: 8:26:38 AM

Page 22: Active Server Page(ASP)

Session Object - Properties

• SessionID– The SessionID property is a unique identifier that is

generated by the server when the session is first created and persists throughout the time the user remains at your web site.

– Syntax:<%Session.SessionID%>

Example:<% Dim mySessionID mySessionID = Session.SessionID %>

Page 23: Active Server Page(ASP)

ASP Cookies

• Like ASP Sessions, ASP Cookies are used to store information specific to a visitor of your website. This cookie is stored to the user's computer for an extended amount of time. If you set the expiration date of the cookie for some day in the future it will remain their until that day unless manually deleted by the user.

• Creating an ASP cookie is exactly the same process as creating an ASP Session. We must create a key/value pair where the key will be the name of our "created cookie". The created cookie will store the value which contains the actual data.

Page 24: Active Server Page(ASP)

Create Cookies

<%

'create the cookie

Response.Cookies("brownies") = 13

%>

To get the information we have stored in the cookie we must use the ASP Request Object that provides a nice method for retrieving cookies we have stored on the user's computer.

Page 25: Active Server Page(ASP)

Retrieving Cookies

<% Dim myBrownie 'get the cookie myBrownie = Request.Cookies("brownies")Response.Write("You ate " & myBrownie & "

brownies") %>• Display:You ate 13 brownies

Page 26: Active Server Page(ASP)

THANK YOU