Active Server Page - ASP in JavaScript 王金龍、陳彥錚 銘傳大學 資管系.

Slides:



Advertisements
Similar presentations
E-Commerce CMM503 – Lecture 8 Stuart Watt Room C2.
Advertisements

Maintaining State Between the Client and Server Internet Programming Using VBScript and JavaScript 9.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
1 Chapter 12 Working With Access 2000 on the Internet.
JavaScript Forms Form Validation Cookies CGI Programs.
How does the server format the information it gives to the appln program? As environment variables and in standard input.
Web Servers How do our requests for resources on the Internet get handled? Can they be located anywhere? Global?
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
Client State Management & Application Security  Client State Management  Concept  ASP Examples  Application Security  Database Based Approach 
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Common Gateway Interface
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Overview A plain HTML document is static A CGI program is executed in real-time, so that it can output dynamic information. CGI (Common Gateway Interface)
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
1 Web Server Concepts Dr. Awad Khalil Computer Science Department AUC.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 1.
Implementing ISA Server Publishing. Introduction What Are Web Publishing Rules? ISA Server uses Web publishing rules to make Web sites on protected networks.
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
CIS 375—Web App Dev II ASP II. 2 ASP Session: Introduction The Session _______ is used to store information about, or change settings for a user session.
State Management. What is State management Why State management ViewState QueryString Cookies.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 21 - Web Servers (IIS, PWS and Apache) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Database-Driven Web Sites, Second Edition1 Chapter 5 WEB SERVERS.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Chapter 6 Server-side Programming: Java Servlets
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
Perl CGI What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. Perl have a *very* nice interface to create CGI.
ASP.NET Dynamic Styles Response and Request Objects.
Form Data Encoding GET – URL encoded POST – URL encoded
Lecture Note 8: ASP Including Files and The Global.asa file.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
ASP Objects Active Server Pages (cont..) 1. 2 ASP : Objects ASP provides built-in objects for performing useful tasks that simplify web development.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP (COMPONENTS) Active Server Pages (cont..) 1. global.asa file The Global.asa file is an optional file that can contain declarations of objects, variables,
ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.
WEB SERVER SOFTWARE FEATURE SETS
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Maintaining State in ASP. Problem - How do I maintain state information about the user  Several Methods –Cookies –Session variables –Hidden fields 
Active Server Pages Session - 3. Response Request ApplicationObjectContext Server Session Error ASP Objects.
7-1 Active Server and ADO Colorado Technical University IT420 Tim Peterson.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Server Object Server Object. The Server object represents a programmable interface to the HTTP service that provides a mechanism to administer and control.
ASP Explained By: Sarbjit Kaur.
z/Ware 2.0 Technical Overview
The Request & Response object
ASP.
Browser and Server Models
Configuring Internet-related services
Chapter 2 Interacting with the Customer
Environment Variables
Cookies A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer.
Presentation transcript:

Active Server Page - ASP in JavaScript 王金龍、陳彥錚 銘傳大學 資管系

Content u Introduction u Object Models u Request Object u Response Object u Server Object u Application and Session Objects u Installable Components for ASP

Introduction u Microsoft’s newest server-based technology for building dynamic interactive web pages u No compiler u Text editor u Browser independent u Object-oriented u Compatible to any ActiveX scripting u Transparent to users

ASP Usage Active Server Scripting Active Server Scripting

Complete ASP Program … Script which run in the browser Script which run in the server …

Server-side includes u u Include text files in pages u Virtual file addresses u u Physical file addresses u

Top Next Previous Top Next Previous … Form Use <% Response.Write(Request.Form("text1")); %>

Basic Statements u u Output a string ( more readable ) VarExpression% u or u Insert a string u u Redirect to the URL u

An ASP Example <% num=Request.Form("numOfHr"); msg="Welcome to My ASP Example!"; %> An ASP Example You are ! Iteration <% Response.Write(" "); } %>

Please input a number: Your Name: aspExample1.html

An ASP Example You are Yen-Cheng Chen ! Welcome to My ASP Example! Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5 Source File in Web Client

Built-In ASP Objects u Request Object u To retrieve the values that the client browser passed to the server during an HTTP request. u Response Object u To send output to the client. u Server u Provide utility functions on the server.

Built-In ASP Objects (cont.) u Application u To share information among all users of a given application. (Like global variables) u Session u To store information needed for a particular user-session. (Like local variables) u ObjectContext u To commit or abort a transaction, managed by Microsoft Transaction Server (MTS).

Client Request Request Object Collection: Form QueryString ServerVariables Cookie ServerVariables Cookie ClientCertificate ClientCertificate Response Response Object Collection: Cookie (Properties) (methods) Server Server Object (method) Application Application Object (properties) (methods) Session Session Object (properties) (methods) Server

Request Object u Provide all the information about the user’s request to applications u Collection u A data store that can store values by linking each one to a unique key

Collections in Request Object u Five collections u QueryString u QueryString: HTTP query string (GET) u Form u Form: Form elements (POST) u ServerVariables u ServerVariables: HTTP and environment variables u Cookie u Cookie: Cookie sent from the browser u ClientCertificate u ClientCertificate: Certificate values (SSL: https) u Usage variable = Request.collectionName(“key”)

Properties and Methods u Properties u TotalBytes: Read-only. Specifies the total number of bytes the client is sending in the body of the request. u Methods  BinaryRead( count ): Retrieves data sent to the server from the client as part of a POST request.

QueryString Collection: Get u The names and values of form are put into a query string u The amount of data can be sent is limited to around 1000 characters u Usage u variable = Request.QueryString(“name”)

queryTest.asp Query String Test ASP You are You are years old. queryTest.asp?name=Mickey+Mouse&age=50

Passing Name=Value Pairs with a Query String Sams Publishing Passing Name=Value Pairs with a Query String Sams Publishing Getting Name=Value Pairs with a Query String name = pub =

Form Collection: Post u The name and values of the form are encoded into the request header u Usage u variable = Request.Form(“name”)

the form text1: radio1: yes no select1: option 1 option 2 option 3 select2: (multiple) option 1M option 2M option 3M textarea1: formTest.html

Form Test ASP text1 radio1 select1 <%num=Request.Form("select2").Count; for (i=1;i select2 hidden1 textArea1 formTest.asp

ServerVariables Collections u Provide HTTP header that is sent by a client browser u To Retrieves the values of predetermined environment variables. u Usage u variable = Request.ServerVariables(“HeaderType”)

AUTH_TYPE = CONTENT_LENGTH = CONTENT_TYPE = GATEWAY_INTERFACE = LOGON_USER = PATH_INFO = PATH_TRANSLATED = QUERY_STRING = REMOTE_ADDR = REMOTE_HOST = REMOTE_METHOD = SCRIPT_MAP = SCRIPT_NAME = SERVER_NAME = SERVER_PORT = SERVER_PORT_SECURE = SERVER_PROTOCOL = SERVER_SOFTWARE = URL =

ALL_HTTPAll HTTP headers sent by the client. ALL_RAWAll headers in the raw-form. APPL_MD_PATH The metabase path for the (WAM) Application for the ISAPI DLL. APPL_PHYSICAL_PATH Retrieves the physical path corresponding to the metabase path. AUTH_PASSWORD The value entered in the client's authentication dialog. AUTH_TYPE The authentication method that the server uses to validate users. AUTH_USERRaw authenticated user name. CERT_COOKIEUnique ID for client certificate, Returned as a string. CERT_FLAGS bit0 is set to 1 if the client certificate is present. bit1 is set to 1 if the client Certifying Authority is invalid. CERT_ISSUER Issuer field of the client certificate. CERT_KEYSIZENumber of bits in Secure Sockets Layer connection key size. CERT_SECRETKEYSIZE Number of bits in server certificate private key. CERT_SERIALNUMBER Serial number field of the client certificate. CERT_SERVER_ISSUER Issuer field of the server certificate. CERT_SERVER_SUBJECT Subject field of the server certificate. CERT_SUBJECT Subject field of the client certificate. CONTENT_LENGTH The length of the content as given by the client. CONTENT_TYPE The data type of the content. GATEWAY_INTERFACE The revision of the CGI specification used by the server. HTTP_ The value stored in the header HeaderName. HTTPSON : if the request came in through secure channel (SSL). OFF : Otherwise.

HTTPS_KEYSIZENumber of bits in Secure Sockets Layer connection key size. HTTPS_SECRETKEYSIZE Number of bits in server certificate private key. HTTPS_SERVER_ISSUERIssuer field of the server certificate. HTTPS_SERVER_SUBJECTSubject field of the server certificate. INSTANCE_ID The ID for the IIS instance in textual format. INSTANCE_META_PATH Metabase path for the IIS instance that responds to the request. LOCAL_ADDR Returns the Server Address on which the request came in. LOGON_USER The Windows NTR account that the user is logged into. PATH_INFOExtra path information as given by the client. PATH_TRANSLATEDA translated version of PATH_INFO (virtual-to-physical) QUERY_STRINGQuery information after ? in the HTTP request. REMOTE_ADDRThe IP address of the remote host making the request. REMOTE_HOSTThe name of the host making the request. REMOTE_USERUnmapped user-name string sent in by the User. REQUEST_METHODThe method used to make the request. SCRIPT_NAMEA virtual path to the script being executed. SERVER_NAMEThe server's host name, DNS alias, or IP address. SERVER_PORTThe port number to which the request was sent. SERVER_PORT_SECURE1 : If the request is on the secure port. 0 : Otherwise. SERVER_PROTOCOL The name and revision of the request information protocol. SERVER_SOFTWAREThe name and version of the server software. URLGives the base portion of the URL.

Cookie Collection u The cookie is a text file stored on the client u Use Request object to access the cookie u Read only u To change cookie: Use Response object u Usage u variable = Request.Cookies(“cookieVariable”)

Response Object u To send output to the client u Collection: Cookie u Properties u Buffer u CacheControl u Charset u ContentType u Expires u ExpiresAbsolute u isClientConnected u Pics u Status u Method  AddHeader( name, value )  AppendToLog( string )  BinaryWrite( data ) u Clear() u End() u Flush()  Redirect( url )  Write( variant )

Response Object: Classification u Insert information u Write(), BinaryWrite() u Send cookie: Cookie u Redirecting: Redirect() u Buffering the page u Buffer, Flush(), Clear(), End() u Setting the properties of a page u Expires, ExpiresAbsolute, CacheControl, ContentType, AddHeader, Status

Inserting Information  Response.Write(“ string ”) u Insert a string into the HTML output u Convert the text to an appropriate character set u  Response.BinaryWrite( data ) u Prevent the conversion

Sending Cookies u Response.Cookies(“CookieName”)=“data” u Response.Cookies(“CookieName”).Expires=“11/26/ :35:00” u Response.Cookies(“CookieName”).Domain=“/netnt.mcu.edu.tw/” u Response.Cookies(“CookieName”).Path=“/u99” u Response.Cookies(“CookieName”).Secure=True u Multiple Value Cookie <% Response.Cookies(“CookieName”)(“item1”)=“data1” Response.Cookies(“CookieName”)(“item2”)=“data2” %>

Redirecting the Browser u Refer users to alternative web pages u Redirection header u Tell the browser to go and get the information elsewhere u Usage u Response.Redirect(“URL”)

Buffering the Page u An extra degree of control over u When a client receives information u What they receive u Usage u Response.Buffer = True ’Default is false u Response.Flush() ’Send the current content u Response.Clear() ’Clear the current buffer u Response.End() ’Stop processing and send u When reach the end, the contents are sent

Server Object u The roof of the object model u Provides access to methods and properties on the server. u Most of these methods and properties serve as utility functions. u Property u ScriptTimeout: Amount of time a script can run u Method  CreateObject( progID )Create an instance of an object  HTMLEncode( string )HTML Encoding  URLEncode( string )URL Encoding  MapPath( path ) Convert a virtual path to a physical path

ScriptTimeout Property u Define the delay before all scripts are terminated u Default = 90 seconds u Usage  Server.ScriptTimout = nn;

HTMLEncode Method u Replace the angle-brackets with an escape sequence u Server  Client ”) %>

URLEncode Method u Convert a string into URL-encoded form u Space  + u Special chars  %nn ”> 33 % 33%

MapPath Method u Provide file location information for use in scripts u Logical path  Physical path u Usage u PhyPath = Server.MapPath(“/clipper”) u e:\clipper u /path: virtual directory u path: relative path

CreateObject Method u Invoke objects on the server u Extend the use of server components u Usage u Set obj = Server.CreateObject(“ProgId”) u Use the methods and access the properties of the object u IsObject( obj ) u Check if the object is created successfully

<% textfile = Server.MapPath("/app5")+"\\test1.html" fsObject = Server.CreateObject("Scripting.FileSystemObject") outStream= fsObject.CreateTextFile(textfile, true, false) myString = " File " outStream.WriteLine(mystring) now=new Date() myString = "The time is " + now.toLocaleString() outStream.WriteLine(mystring) outStream.WriteLine(" ") outStream.close() Response.Write(" My New Text File ")%>

Application Object u To share information among all users of a given application. u An ASP-based application is defined as all the.asp files in a virtual directory and its subdirectories. u Collections  Contents : Contains all of the items that have been added to the Application.  StaticObjects : Contains all of the objects added to the session with the tag.

Application Object (cont.) u Methods  Lock : Prevents other clients from modifying Application object properties.  Unlock : Allows other clients to modify Application object properties. u Events  Application _ OnEnd : Occurs when the application quits  Application _ OnStart : Occurs when a page is first referred. u Scripts for the preceding events are declared in the global.asa file.

Application Object u Usage Application.Lock() Application(“name”)=“value” Application.Unlock() u Event handles: u global.asa in the root directory of the virtual mapping function Application_OnStart() { … } function Application_OnEnd() { … }

Example - Application Object <% Application.Lock() Application("NumVisits") = Application("NumVisits") + 1 Application.Unlock() %>... This application page has been visited times! function Application_OnStart(){ Application(“NumVisits”)=0; } Global.asa

Application Object u Application Life u Start u The application starts the first time any client requests a document from that virtual mapping u End u The web server is stopped by the operating system

Please enter your name: Please enter your age: Please select which city your are living in: Seattle Denver Miami appTest.html

<% Application.Lock() Application("name") = ""+Request.Form("name") Application("age") = ""+Request.Form("age") Application("city") = ""+Request.Form("city") Application.Unlock() %> Hello, thank you The weather in is grey skies and plenty of rain. <% } else if (Application("city") = = "Denver") { %> The weather in is cold and snowy. The weather in is warm and sunny. appTest.asp

Session Object u Share data between different pages, but not between different clients u Session information is maintained on an individual client basis u Global to that client u A Session object is created when the client first makes a document request and destroyed 20 minutes after the last request.

Session Object u To store information needed for a particular user- session. u Variables stored in the Session object are not discarded when the user jumps between pages in the application u Collections  Contents : Contains the items that you have added to the session with script commands.  StaticObjects: Contains the objects created with the tag and given session scope.

u Properties u CodePage: Codepage used for symbol mapping. u LCID: Locale identifier. u SessionID: Session identification for this user. u Timeout: Timeout period for the session state, in minutes. u Methods u Abandon( ): Destroys a Session object and releases its resources. u Events (used in Global.asa)  Session _ OnEnd: Session Timeout or abandoned u Session_OnStart: When server creates a new session u Usage: Session(“name”)=“value” Session Object (cont.)

SessionID Property u When store information in the Session object, the client is assigned a SessionID u Used to identify session u Actually be stored as a cookie with no expiry data set u Usage u Session.SessionID

Event Handler u global.asa … function Session_OnStart() { … ’first request a document } function Session_OnEnd() { …’Timeout or Abandon }

Summary u Object Models u Use Request Object to receive client's request. u Use Response Object to control the output to the client. u Use Server Object to access server utilities and objects. state u Use Application and Session Objects to maintain the web state.

Installable Components for ASP u Ad Rotator (AdRotator) u Ad Rotator (AdRotator): Automatically rotates advertisements displayed on a page according to a specified schedule. u BrowserCapabilities(BrowserType) u Browser Capabilities (BrowserType): Determines the capabilities, type, and version of Browser. u Database Access (ADO) u Database Access (ADO): Provides access to databases. u Content Linking (NextLink) u Content Linking (NextLink): Creates tables of contents. u File Access (FileSystemObject) u File Access (FileSystemObject): Provides access to file I/O. u Collaboration Data Objects for NTS Component u Collaboration Data Objects for NTS Component: Sends and receives messages to your Web page.

Installable Components for ASP (cont.) u Tools (Tools) u Tools (Tools): Enables you to add sophisticated functionality to your web pages. u MyInfo (MyInfo) u MyInfo (MyInfo): Keeps track of personal information. u Counters (Counters) u Counters (Counters): Creates, stores, increments, and retrieves individual counters. u Content Rotator (ContentRotator) u Content Rotator (ContentRotator): Automates the rotation of HTML content strings on a Web page. u Page Counter (PageCounter) u Page Counter (PageCounter): Counts and displays the number of times a Web page has been opened. u Permission Checker (PermissionChecker) u Permission Checker (PermissionChecker): Determines whether a Web user has been granted permissions to read a file.