elements of asp documents adapted from mcdn web workshop ( and webmonkey’s introduction to active

14
Elements of ASP Documents Adapted from MCDN Web Workshop (http:// msdn.microsoft.com/workshop/server/asp/ASP over.asp ) and Webmonkey’s Introduction to Active Server Page ( http://hotwired.lycos.com/webmonkey/98/39/ index2a.html )

Upload: britton-powell

Post on 29-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Elements of ASP Documents

Adapted from MCDN Web Workshop (http://msdn.microsoft.com/workshop/server/asp/ASPover.asp)

andWebmonkey’s Introduction to Active Server Page

(http://hotwired.lycos.com/webmonkey/98/39/index2a.html)

Page 2: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Server Side Scripting

Javascript: universally used on the browser for client side scripting.

php, pearl, ASP, ASP.NET, JSP: used for client side scripting.

Client side scripting can capture input from client forms and write email; connect to DB, search DB, and return information to clients.

Page 3: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

What is Active Server Page?

A specification for a dynamically created Web page. When the browser requests an ASP document, the server creates an HTML page on the fly and sends it to the client. ASP refers to: Microsoft technology for Server-side scripting

Can combine HTML, VBScript, Javascript, ADO Web document that contains ASP code

Has extension .asp

Page 4: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

What Can You Do with ASP?

Put Employee records on-line, so that they can be updated by individuals--e.g., health plan

Tie on-line store to existing inventory database

Allow visitor to a Web site for only that information the person seeks

Page 5: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

ASP Cycle

Browser Server

ASP Engine

Com Objects

1

4

5

7 2

6 3

1. Browser requests ASP page from server

2. Server sends ASP page to ASP engine

3. ASP engine executes server-side scripts

4. ASP calls for COM* objects (when needed)

5. COM object retrieved (when asked)

6. ASP engine sends HTML stream to server

7. Server sends HTML code to browser

*COM: Component Object Model—MS-developed standards to allow programmers to access OLE and Active X objects

Page 6: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

ASP Statements

ASP uses the delimiters "<%" and "%>" to enclose script commands. For example, the following code sets the value of the variable "MyFavTVShow" in the user cookie to "I Dream of Jeannie."

<%Response.Cookies("MyFavTVShow =” & _ "I Dream of Jeannie”)%>

Page 7: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Code Example 1

<FONT COLOR="GREEN"> <%If Time >= #12:00:00 AM# And Time < #12:00:00 PM# Then%> Good Morning! <%Else%> Hello! <%End If%> </FONT>

The following code segment prints appropriate greeting to a Web page depending on the time of day.

Page 8: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Built-in Objects

ASP includes five standard objects for global use: 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 settings and change

them for the user's current Web-server session Application—to share application-level information and

control settings for the lifetime of the application

Page 9: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Methods for Response Object

AddHeader—Adds an HTML header with a specified value

AppendToLog—Appends a string to the end of the Web server log file

BinaryWrite—writes binary data (i.e, Excel spreadsheet data)

Clear—clears any buffered HTML output.

End—stops processing of the script.

Flush — sends all of the information in the buffer.

Redirect—to redirect the user to a different URL

Write—to write into the HTML stream.

Page 10: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Writing to HTML Document

<% Response.write("hello”) %>

or the shortcut command

<%="hello"%>

Page 11: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Methods for Server Object

CreateObject—to create an instance of a server component. This component can be any component that you have installed on your server (such as an ActiveX ).

HTMLEncode—to encode the specified string in HTML.

MapPath—to map the current virtual path to a physical directory structure. You can then pass that path to a component that creates the specified directory or file on the server.

URLEncode—applies URL encoding to a specified string.

Page 12: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Code Example 2

<%@ Language=VBScript %><!doctype html public "-//w3c//dtd html 3.2//en"><html><head><title>Test an ASP</title></head><body bgcolor="cccc66" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><h1>This part is from HTML.</h1><% Response.Write("This line is from VBScript.") %><br><% Response.Write("<h1><font color=#0000ff>This is another line from VBScript.</font></h1>")%></body></html>

Click here for result

Page 13: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active

Click here for HTML code

Page 14: Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active