web basics isys546. basic tools web server –default directory, default home page –virtual...

40
Web Basics ISYS546

Post on 21-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Web Basics

ISYS546

Page 2: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Basic Tools

• Web Server– Default directory, default home page– Virtual directory

• Web Page Editor– Front Page

• Web Languages– HTML, XML– Client-side script language:

• VBScript, JavaScript

– Server-side language: VB .NET, ASP .NET

Page 3: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Dynamic Web Pages

• Demo: TimeNow– <body>– <p>The time is now <%=time()%></p>– <p>The time is now <% response.write time()%></p>

– <%– dim iHour– iHour=hour(time())– if iHour < 12 then– response.write "good morning"– else– response.write "<h1>good

afternoon</h1><br>"– end if– %>

Page 4: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Client-Side vs Server-Side Scripting

• Client-side scripting:– The browser requests a page.– The server sends the page to the browser.– The browser sends the page to the script engine.– The script engine executes the script.

• Server-side scripting:– The browser requests a page.– The server sends the page to the engine.– The script engine executes the script.– The server sends the page to the browser.– The browser renders the page.

• Demo: ShowSum.htm, Web Form

Page 5: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

HTML Introduction

• Heading section– <head>, <title>, <meta>, <script>, etc.

• Body section– <body>, <p>, <h1> to <h6>, <a>, <br>– Formatting: <b>, <I>, <u>, <center>– Comment: <!-- comment -->– List <ul>– Image– Table: <table>, <tr>: a new row in table, <td>: a new cell in

a table row.– Form: <form>, <input>, <select>, <textarea>

Page 6: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Webpage Editor

• FrontPage demo

• Demo: Use Response.write to write the html code generated by FrontPage.

Page 7: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

META Tag

• The meta tag allows you to provide additional information about the page that is not visible in the browser:– <meta name=“Author” content=“D Chao”>– <meta name=“Keywords” content=“apple,

orange,peach”>

• Redirection:– <meta http-equiv=“refresh”

content=“3;url=http://www.sfsu.edu”>• “3” is number of seconds.• Demo: Redirect.htm

Page 8: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

TABLE Tag

<table border="1" width="100%"> <tr> <td width="25%"></td> <td width="25%">&nbsp;</td> <td width="25%">&nbsp;</td> <td width="25%">&nbsp;</td> </tr> <tr> <td width="25%">&nbsp;</td> <td width="25%">&nbsp;</td> <td width="25%">&nbsp;</td> <td width="25%">&nbsp;</td> </tr></table>

Page 9: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

FORM Tag

• Form attribute:– Action: Specify the URL of a program on a server or an

email address to which a form’s data will be submitted.– Method:

• Get: the form’s data is appended to the URL specified by the Action attribute as a QueryString.

• Post: A prefered method for database processing. Form’s data is sent separately from the URL.

– Name: Form’s name– Target: Specified a window in which results returned

from the server appear.

Page 10: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

QueryString

• A QueryString is a set of name=value pairs appended to a target URL.

• It can be used to pass information from one webpage to another.

• To create a QueryString:– Add a question mark (?) immediately after a URL.– Followed by name=value pairs separated by

ampersands (&).

• Example: • <A Href=“http://my.com/Target.htm?CustID=C1&Cname=Chao”>

Page 11: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Creating a QueryString

• User typed URL

• As part of a URL specified in an anchor tag.

• Via a form sent to the server with the GET method.– Demo: TestReqFormQ.htm

Page 12: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Client-Side Script Tag

• <SCRIPT LANGUAGE = VBSCRIPT>

• <SCRIPT LANGUAGE = JAVASCRIPT>

• HTML and Vbscript are not case-sensitive; Javascript is case-sensitive, each statement ends in a semicolon (;).

Page 13: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Script Example

<SCRIPT LANGUAGE=vbscript>

<!--

statements

-->

</SCRIPT>

Page 14: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

<body>

<p>Hello World</p>

<script language="javascript1.3">

document.write ("<h1>Hello world</h1>");

</script>

</body>

Page 15: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Variable Declaraton

• JS: var intrate, term, amount;• VB: dim intrate, term, amount• Data Type:

– Variant - a variable’s data type is determined when it is initialized to its first value.

• Variable scope:– Local: Variables declared in a function or procedure.

– Global: Variables declared in the heading section, but not in a function or procedure.

Page 16: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Arrays

• JS: var arrayName = new Array(array size);• var Pet = new Array(2);

• Pet[0]=“dog”;

• Pet[1]=“cat”;

• Pet[2]=“bird”;

• VB: dim arrayName(array size)• Dim Pet(2)

• Pet(0)=“dog”

• Pet(1)=“cat”

• Pet(2)=“bird”

Page 17: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Comments

• JS: – Single-line comment: //– Multiple-line comments: /* … */

• VB: single quotation mark ‘

Page 18: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Operators• Arithmetic operators:

– JS: +, -, *, /, Math.pow(x,y), etc.• Math is an object with many methods such as round(x),

random(), sqrt(x), ceil(x), floor(x), etc.

– JS: Prefix operator: ++VarName, --VarName• Postfix operator: varName++, varName--

– VB:+. -, *, /, ^

• Comparison operators:– JS: = = , !=, <, >, <=, >=– VB: =, <>, <, >, <=, >=

• Logical operators:– JS: &&, ||, !– VB: AND, OR, NOT

Page 19: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

IF Then StatementsJS: if (condition) {

statements;

}

else {

statements;

}

VB: if (condition) then

statements

else

statements

end if

Page 20: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Case StatementsJS: Switch Case Statement

switch(varable name) {case value1:

statements;break;

case value2:statements;break;

…default:

statements;break;

}

VB: Select Case statement

Page 21: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Loop StructuresJS: 1. while (condition) {

statements;}

2. do{statements;

} while (condition)

3. for (var I = 0; I<5;I=I+1){statements;

}

Page 22: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

JavaScript Build-In Objects and Methods

• Math object• String object: In JS, a string variable is an object

and can be created by:– varName = “Smith”– varName = new String(“Smith”)

• String object methods:– bold, fontcolor, fontsize, toLowerCase, toUpperCase– anchor (create a bookmark), link (create a link)– Substring, split (split a string into an array)

Page 23: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Examples of Using String’s Methods

var test = “Click Here”;

var website = http://www.sfsu.edu;

test.link(website);

var test = “one, two, three”;

var newArray = test.split(“,”);

Note: split is useful in parsing a queryString.

Page 24: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

JavaScript’s Conversion Functions

• toString() example:• Price=5;

• Qty=10;

• Amount=Price*Qty;

• Document.write (Amount.toString());

• Eval• strVar = “5”;

• numVar = eval(strVar)

Page 25: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

JavaScript Functions

• Defining functions– function functionName(arg1,..,argN){

• Statements;• return return value;

– }

Note: 1. The arguments are optional.2. The return statement is optional. A function is not

required to return a value.

Page 26: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

VBScript Functions

• Defining functions:– Function functionName(arg1,..,argN)

• Statements

• functionName=returnValue

– End Function

– Note: Unlike VB, a function is not required to return a value.

Page 27: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Browser Object Model

N avig a to r L oca tion

Text

R ad io

C h eckB ox, e tc

F orm co llec tion

Im ag e

L in k

A n ch or, e tc

O th er co llec tion s

D ocu m en t H is to ry F ram e

W in d ow

Page 28: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Window Object

• The Window object represents a Web browser window.

• We use the properties and methods of a Window object to control browser window.

Page 29: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Window Object• Properties:

– window.status, window.defaultstatus– window.document, window.history, window.location.– Window.name

• Methods:– window.open (“url”, “name”, Options)

• Options: menubar=no, status=no, toolbar=no, etc.

– window.close– window.alert(“string”)– window.prompt(“string”)– Window.confirm()– window.prompt(“string”, “default string”)– window.focus() , window.blur() :set/remove focus– Window.setTimeout(“statements”, milliseconds)

Page 30: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Document Object

• The document object represents the actual web page within the window.

• Properties: – background, bgColor, fgColor, title, url, lastModified,

domain, referrer, cookie, linkColor, etc. • Ex. document.bgColor=“silver”;

• Methods: – Document.write (“string”)– Document.open, close

• Demo (testDOm.htm, docProp.htm, testDoc.htm)

Page 31: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Navigator Object

• The navigator object provides information about the browser.

• Properties:– Navigator.appName:browser name– Navigator.appCodeName: browser code name– Navigator.appVersion– Navigator.platform: the operating system in

use.

Page 32: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Location Object• Allows you to change to a new web page from

within a script code.• Properties:

– Host, hostname, pathname– Href: full URL address– Search: A URL’s queryString

• Methods:– location.reload()– location.replace(); replace current page and old page’s

entry in the history.

• To open a page: location.href = “URL”• Demo: TestLocation.htm

Page 33: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

History Object

• Maintain a history list of all the documents that have been opened during current session.

• Methods:– history.back()– history.forward()– history.go(): ex. History.go(-2)

• Demo: testDocOpenClose.htm

Page 34: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Client-side Scripting with the Browser Object Model<script language=JavaScript1.3>

window.status = "Testing DOM"

</script>

<title>New Page 1</title>

</head>

<body>

<script language=JavaScript1.3>

if (navigator.appName == "Netscape")

{

document.write("you are using Netscape!");

}

else

{

document.write("You are using Explorer!");

}

email=window.prompt("Enter email: ");

window.alert ("your enail is:" + email);

site=window.prompt("enter url:");

window.open (site);

// document.open();

document.write("today is: " + Date());

//JavaScript is case-sensitive: Date(), not date().

</script>

<script language=vbscript>

email=window.prompt("Enter email: ")

window.alert ("your enail is:" & email)

site=window.prompt("enter url:")

window.open (site)

document.open()

document.write("today is: " & Date())

</script>

</body>

</html>

Page 35: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Testing the History Object

<html><script language=vbscript><!--sub clearVB()document.write ("hello, this is a new page")window.alert("Press any key to continue")document.open()document.write ("<h1>This is another new page</h1>")document.closewindow.alert("Press any key to go back")history.go(-2)end sub--></script><head><title>New Page 1</title></head><body><p>this is old info</p><script language=vbscript>document.write ("<p>this is another old info</p>")</script><p><input type="button" value="clear" name="B3" onCLick="clearVB()"><p>&nbsp;</p></body></html>

Page 36: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Testing Location Object<html>

<script language=vbscript>

function openNew()

site=window.prompt("enter url:")

window.open (site)

location.href="showformdata.htm"

end function

</script>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta name="GENERATOR" content="Microsoft FrontPage 4.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<title>New Page 1</title>

</head>

<body>

<p><input type="button" value="Button" name="B3" onclick="openNew()"></p>

</body>

</html>

Page 37: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

HTML Tags and Events

• Link <a> </a>: click, mouseOver, mouseOut• Image <img>: abort(loading is interrupted), error,

load.• Area <area>: mouseOver, mouseOut• Body <body>: blur, error, focus, load, unload• Frameset: blur, error, focus, load, unload• Frame: blur, focus• Form: submit, reset• Textbox, Text area: blur, focus, change, select• Button, Radio button, check box: click• List: blur, focus, change

Page 38: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Event Handler

• Event handler name: on + event name– Ex. onClick

• Three ways of writing handler:– 1. Within the tag

• <input type = “button” name =“ button1” value “click here” onCLick = window.alert(“you click me”)>

– 2. Event function: onCLick=“clickHandler()”

– 3. Event procedure as in VB.• Sub button1_onCLick()

Page 39: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Form Object• Form Input/Select object:

– Textbox, radio button, check box, drop-down list box, text area, push button, submit button, reset button.

• Event-Handler:– onBlur (lose focus), onCHange, onClick, onFocus,

onKeyDown, onKeyPress, onKeyUp, onLoad (when a document is loaded), onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onReset(when click the reset button), onResize(when window is resized), onSubmit.

• Refer an input object in a form:– document.formname.inputobjName.Value

• Demo: showFormData.htm

Page 40: Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML

Forms Collection

• The forms collection is a collection of form objects within the document object.

• To retrieve a form’s`property:– document.form[index].property

• Base 0 index

– Document. formname.property