csc317 – internet programming csc318 – dynamic web application development

37
CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES

Upload: ginny

Post on 20-Feb-2016

49 views

Category:

Documents


0 download

DESCRIPTION

CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT. BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES. Outline. Introduction to Server-Side Scripting. How does a server side page work? Introduction to IIS/PWS ASP Requirements What is ASP? - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

CSC317 – INTERNET PROGRAMMINGCSC318 – DYNAMIC WEB APPLICATION DEVELOPMENTBY: SITI NURBAYA ISMAILFACULTY of COMPUTER and MATHEMATICAL SCIENCES

Page 2: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Outline

How does a server side page work? Introduction to IIS/PWS ASP Requirements What is ASP? How ASP file looks like? Form Processing Using ASP JavaScript vs VBScript Other Server Scripting Language

Page 2

Introduction to Server-Side Scripting

Page 3: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Introduction to Server-Side Scripting

Basically, A Web requires two components: a Web server and a client The client is usually a browser (I.E/Firefox/Chrome/etc) Both the server & the client can communicate each other Must use a defined protocol to communicate The most common protocols are HTTP & FTP and also carried over an

underlying network protocol called TCP/IP The client sends an initialization (is a defined series of bytes) to start a

session, when the server receives the initialization request, it acknowledges the transmission by returning another series of bytes to the client

Page 3

How does a server side page work?

Page 4: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Introduction to Server-Side Scripting

The conversation between client & server continues in this back-and forth manner

You can imagine the conversation being conducted as follows:

Page 4

How does a server side page work?

`

Hello!

Hello

Can you give me index.php file?

Okay, here is the index.php fileClient Side Server Side

Page 5: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Introduction to Server-Side Scripting

You can choose either IIS/PWS as a web server to run your ASP file If you choose IIS, you must have access to a Windows NT 4.0 server with

IIS 4.0 or Windows 2000 Server with IIS 5.0 Or you can install PWS on your local hard disk and enables you to work

as same as IIS PWS/IIS designate a master directory on the hard drive that contains all

date and script file for use by Internet Server

Page 5

Introduction to IIS/PWS

Page 6: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Introduction to Server-Side Scripting

The default master directory is: \Inetpub You can place your ASP file under subdirectory: \wwwroot (Example: C:\

Inetpub\wwwroot\MyFirstAsp.asp) IIS/PWS have built-in intelligence that knows to route a request for a Web

page using HTTP to this directory.

Page 6

Introduction to IIS/PWS

Page 7: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Introduction to Server-Side Scripting

Page 7

ASP Requirements

Page 8: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 8

Introduction to Server-Side Scripting

Stands for Active Server Pages An ASP is a Web page that is processed by a web server ASP is a Microsoft technology ASP is a program that runs inside a web server (IIS/PWS) An ASP file is just the same as an HTML file An ASP file can contain text, HTML, XML, and scripts An ASP file has the file extension ".asp"

What is ASP?

Page 9: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 9

Introduction to Server-Side Scripting

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 Provides security since your ASP code can not be viewed from the browser Since ASP files are returned as plain HTML, they can be viewed in any browser Clever ASP programming can minimize the network traffic

What ASP can do?

Page 10: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 10

Introduction to Server-Side Scripting

At top of the ASP file, we have this line of code

You can place ASP code anywhere in the ASP file, BUT the code must be within its opening and closing delimiters tag

How ASP file looks like?

<%@LANGUAGE = “JAVASCRIPT”%>

<%// the rest of your ASP code%>

Page 11: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 11

Introduction to Server-Side ScriptingHow ASP file looks like?

<%@LANGUAGE=“JAVASCRIPT”%><%// it can be here%><html><head><title></title></head><body><%// it can be here%></body></html><%// it can be here%>

Page 12: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 12

Introduction to Server-Side ScriptingHow ASP file looks like?

<%@LANGUAGE="JAVASCRIPT"%><html><head><title>My First ASP Page</title></head><body><% Response.Write("Hello World!"); %></body></html>

Page 13: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 13

Introduction to Server-Side Scripting

Remember how to create a complete HTML form with input fields?

Form Processing Using ASP

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%><html><head><title>HTML and ASP</title></head><body><form name="form1" method="post" action="login.process.asp"> <p>Username: <input name="username" type="text" id="username"></p> <p>Password: <input name="password" type="password" id="password"></p> <p><input name="Login" type="submit" id="Login" value="Login"></p></form></body></html>

Page 14: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 14

Introduction to Server-Side Scripting

Okay, save that file on the previous slide as login.asp Notice that there is a value in action=“login.process.asp” It means, the

login process will be done at another ASP file, which is login.process.asp

Form Processing Using ASP

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%><%if(Request.Form("Login") == "Login"){

var username, password;username = Request.Form("username");password = Request.Form("password");Response.Write("Username: " + username + "<br>");Response.Write("Password: " + password);

}%>

Page 15: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 15

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>// as usual, code above is compulsory<%// code below means, if Login button is clicked, then the code block will // be executedif(Request.Form("Login") == "Login"){

// variables declarationvar username, password; // 2 lines of codes below, show how to capture inputs from HTML// formusername = Request.Form("username");password = Request.Form("password");// 2 lines of codes below, show how to display the values on the// web pageResponse.Write("Username: " + username + "<br>");Response.Write("Password: " + password);

}%>

Page 16: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 16

Introduction to Server-Side Scripting

Why do we need to create a code if a button is clicked?

- To execute a specific code once the button is clicked- Sometimes, in a single form, we have more than 1 buttons. Each 1 has its own

specific (code|task)- By doing so, the system knows which code to be executed depending on

which button has been clicked

Form Processing Using ASP

<%// code below means, if Login button is clicked, then the code block will // be executedif(Request.Form("Login") == "Login"){

// code block to be executed if button is clicked}%>

Page 17: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 17

Introduction to Server-Side Scripting

Why do we need to create a code if a button is clicked?

Form Processing Using ASP

<%/* 1. code below means, if “Login” button is clicked, then the code block will be executed2. “Login” name can be replaced with any name, depending on the name of button you specified in the form*/if(Request.Form("Login") == "Login"){

// code block to be executed if button is clicked}%>

Page 18: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 18

Introduction to Server-Side Scripting

How to capture inputs from HTML form?

- Similar to JavaScript, you need to declare variables to hold values captured from form

- Request.Form(“<your_field_name>”) is used to capture the values before assign to variable- <your_field_name> is depending on names of input fields from text field,

drop down list, text area, radio button, and checkbox

Form Processing Using ASP

<%// variables declarationvar username, password; /* 2 lines of codes below, show how to capture inputs from HTML form */username = Request.Form("username");password = Request.Form("password");%>

Page 19: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 19

Introduction to Server-Side Scripting

How to display value on the web page?

- Did you find any similarity with JavaScript? In JavaScript, we use document.write() to display an output, BUT in ASP, we use Response.Write() for the same purpose

- To concatenate join several (text|codes), we use plus (+) symbol

Form Processing Using ASP

<%/* 2 lines of codes below, show how to display the values on the web page*/Response.Write("Username: " + username + "<br>");Response.Write("Password: " + password);%>

Page 20: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 20

Introduction to Server-Side Scripting

How to redirect from 1 page to another in ASP?- Sometimes, after we have successfully log into web application, we will be

redirected to the menu page (for example) or any other pages- This can be done by using Response.Redirect(“<url_or_file>”)- “<url_or_file>” can be URL (website address) or ASP files

Form Processing Using ASP

<%if(Request.Form("Login") == "Login"){

Response.Redirect("http://www.google.com/");}%><%if(Request.Form("Login") == "Login"){

Response.Redirect("menu_administrator.asp");}%>

Page 21: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 21

Introduction to Server-Side ScriptingJavaScript vs VBScript

JavaScript VBScript

Case-sensitive Not case-sensitive

Able to be executed on any web browsers

Some web browsers may have problems execute VBScript

<%@LANGUAGE=“JavaScript”%> <%@LANGUAGE=“VBScript”%>

JavaScript is open protocol VBScript is not

More complex Less complex

More powerful than VBScript Less powerful than JavaScript

Page 22: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Introduction to Server-Side Scripting

Scripting Language: programming language that allows control of one or more software applications

JavaScript VBScript Hypertext Preprocessor: PHP

Page 22

Other Server Scripting Language

Page 23: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Outline

Adding server-side scripts into a web page- Inline or intersperse

Using ASP Response.Write to display text on a web page

Page 23

Server-Side Scripting

Page 24: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Outline

The Response Object The Request Object The Session Object

Page 24

Build-in ASP Objects

Page 25: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Outline

The Application & Server Objects Using Form Object

Page 25

Build-in ASP Objects

Page 26: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Outline

Introduction to ADO Accessing data with ADO

Page 26

Accessing Database with ASP and ADO

Page 27: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 27

Introduction to Server-Side Scripting

Response.Redirect(), Response.Write(), Request.Form() You have seen those three ‘things’ in the previous slides What are they? They are called ASP Objects We have:

- ASP Response Object- ASP Request Object- ASP Server Object- And few others

ASP Objects

Page 28: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 28

Introduction to Server-Side ScriptingASP Response Objects

Property Description

Buffer Specifies whether to buffer the page output or not

CacheControl Sets whether a proxy server can cache the output generated by ASP or not

Charset Appends the name of a character-set to the content-type header in the Response object

ContentType Sets the HTTP content type for the Response object

Expires Sets how long (in minutes) a page will be cached on a browser before it expires

ExpiresAbsolute Sets a date and time when a page cached on a browser will expire

Page 29: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 29

Introduction to Server-Side ScriptingASP Response Objects

Property Description

IsClientConnected Indicates if the client has disconnected from the server

Pics Appends a value to the PICS label response header

Status Specifies the value of the status line returned by the server

Page 30: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 30

Introduction to Server-Side ScriptingASP Response Objects

Method Description

AddHeader Adds a new HTTP header and a value to the HTTP response

AppendToLog Adds a string to the end of the server log entry

BinaryWrite Writes data directly to the output without any character conversion

Clear Clears any buffered HTML output

End Stops processing a script, and returns the current result

Flush Sends buffered HTML output immediately

Page 31: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 31

Introduction to Server-Side Scripting

Method Description

* Redirect Redirects the user to a different URL

* Write Writes a specified string to the output

ASP Response Objects

Collection Description

Cookies Sets a cookie value. If the cookie does not exist, it will be created, and take the value that is specified

Page 32: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 32

Introduction to Server-Side ScriptingASP Request Objects

Collection Description

ClientCertificate Contains all the field values stored in the client certificate

Cookies Contains all the cookie values sent in a HTTP request

* Form Contains all the form (input) values from a form that uses the post method

* QueryString Contains all the variable values in a HTTP query string

ServerVariables Contains all the server variable values

Page 33: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 33

Introduction to Server-Side Scripting

Property Description

TotalBytes Returns the total number of bytes the client sent in the body of the request

ASP Request Objects

Method Description

BinaryRead Retrieves the data sent to the server from the client as part of a post request and stores it in a safe array

Page 34: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 34

Introduction to Server-Side ScriptingASP Server Objects

Method Description

* CreateObject Creates an instance of an object

* Execute Executes an ASP file from inside another ASP file

GetLastError Returns an ASPError object that describes the error condition that occurred

HTMLEncode Applies HTML encoding to a specified string

* MapPath Maps a specified path to a physical path

Page 35: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 35

Introduction to Server-Side Scripting

Method Description

Transfer Sends (transfers) all the information created in one ASP file to a second ASP file

URLEncode Applies URL encoding rules to a specified string

ASP Server Objects

Property Description

ScriptTimeOut Sets or returns the maximum number of seconds a script can run before it is terminated

Page 36: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 36

Question?

Page 37: CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT

Page 37

Knuckles (2001). Introduction to Interactive Programming on the Internet using HTML & Javascript. John Wiley & Sons, Inc.

http://www.w3schools.com/asp/default.asp

Bibliography (Book)

Bibliography (Website)