Web Technology - Questions - Answers-1
Web Technology - Questions - Answers-1
UNIT – I
2 MARKS
1. How constants are defined in VBScript?
Constants are defined in VBScript as follows
[Public | Private]ConstConstant_Name =Value
Sub Subroutine_Name(argument1,argument2,argumentn)
…..code within the subroutine
End Sub
22. Give the syntax of For….Next loop in VBScript(JULY.2014)
Syntax:
For counter=start To end [Step step]
[statements]
[Exit For]
[statements]
Next
23. What a class contains in VBScript (APR.2014)
Class is a construct that is used to define a unique type.
Classes can contain variables, properties, methods or events.
24. Name the properties in Error object handling
The Err has the following important properties.
Err.Number - The code value of the runtime error. For example, Err.Number=1, 1 is the code value of
the “Division zero” error.
Err.Description – The description string of the runtime error.
Err.Source – The source string of the runtime error.
5 MARKS
1. Discuss the usage of dictionary object in VBScript (NOV.2012,APR. 2014,JULY 2014,APR. 2016)
The Dictionary object stores name/value pairs(referred to as the key and item respectively) in an array. The
key is a unique identifier for the corresponding item and cannot be used for any other item in the same
Dictionary object.
The following code creates a Dictionary object called “cars”, adds some key/item pairs, retrieves the item
value for the key ‘b’ using the Item property and then outputs the outputting string to the browser.
CODE:
<%
Dim cars
Set cars = CreateObject("Scripting.Dictionary")
cars.Add "a", "Alvis"
cars.Add "b", "Buick"
cars.Add "c", "Cadillac"
Response.Write "The value corresponding to the key 'b' is "
cars.Item("b")
%>
Output:
"The value corresponding to the key 'b' is Buick"
Explanation:
This code creates a Dictionary object called "cars", adds some key/item pairs, retrieves the item value for
the key 'b' using the Item property and then outputs the resulting string to the browser.
2. Explain on any one control statement used in VBScript
Select Case statement:-
We can also use the "Select Case" statement if you want to select one of many blocks of code to
execute:
Syntax:-
The syntax of a Switch Statement in VBScript is:
Select Case expression
Case expression list1
statement1
statement2
....
....
statement1n
Case expression list2
statement1
statement2
....
....
Case expression list n
statement1
statement2
....
....
Case Else
elsestatement1
elsestatement2
....
....
End Select
Example:-
d=weekday(date)
Select Case d
Case 1
response.write("Sleepy Sunday")
Case 2
response.write("Monday again!")
Case 3
response.write("Just Tuesday!")
Case 4
response.write("Wednesday!")
Case 5
response.write("Thursday...")
Case 6
response.write("Finally Friday!")
Case else
response.write("Super Saturday!!!!")
End Select
Procedure_typeProcedure_Name(argument_list)
the procedure heading
declaration statements
execution statements
End Procedure_type
VARIABLES:-
VBScript variables are used to hold values or expressions. A variable can have a short name, like
x, or a more descriptive name, like carname.
Rules for VBScript variable names:
Must begin with a letter
Cannot contain a period (.)
Cannot exceed 255 characters
In VBScript, all variables are of type variant, that can store different types of data.
Declaring (Creating) VBScript Variables:-
Now we have created two variables. The name of the variables are "x" and "carname".
we can also declare variables by using its name in a script. Like this:
carname="Volvo"
Function Description
Int A Function, which returns the integer part of the given number
Log A Function, which returns the natural logarithm of the given
number. Negative numbers disallowed
Oct A Function, which returns the Octal value of the given
percentage
Hex A Function, which returns the Hexadecimal value of the given
number
Rnd A Function, which returns a random number between 0 and 1
Sgn A Function, which returns a number corresponding to the sign of
the specified number
Sqr A Function, which returns the square root of the given number.
Negative numbers disallowed
Abs A Function, which returns the absolute value of the given
number
Exp A Function, which returns the value of e raised to the specified
number
Sin A Function, which returns sine value of the given number
Cos A Function, which returns cosine value of the given number
Tan A Function, which returns tan value of the given number
Function Description
Date A Function, which returns the current system date
CDate A Function, which converts a given input to Date
DateAdd A Function, which returns a date to which a specified time
interval has been added
DateDiff A Function, which returns the difference between two time
period
DatePart A Function, which returns a specified part of the given input
date value
DateSerial A Function, which returns a valid date for the given
year,month and date
FormatDateTime A Function, which formats the date based on the supplied
parameters
IsDate A Function, which returns a Boolean Value whether or not the
supplied parameter is a date
Day A Function, which returns an integer between 1 and 31 that
represents the day of the specified Date
Month A Function, which returns an integer between 1 and 12 that
represents the month of the specified Date
Year A Function, which returns an integer that represents the year
of the specified Date
MonthName A Function, which returns Name of the particular month for
the specified date
WeekDay A Function, which returns an integer(1 to 7) that represents the
day of the week for the specified day.
WeekDayName A Function, which returns the weekday name for the specified
day.
2. ASSIGNMENT OPERATOR:-
Operator Description
= Assign
3. COMPARISON OPERATORS:-
Operator Description
= Is equal to
<> Is not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
4. LOGICAL OPERATORS:-
Operator Description
And Performs a logical conjunction on two expressions (if both expressions
evaluate to True, result is True. If either expression evaluates to False,
result is False)
Or Performs a logical disjunction on two expressions (if either or both
expressions evaluate to True, result is True).
Not Performs logical negation on an expression.
Xor Performs a logical exclusion on two expressions (if one, and only one,
of the expressions evaluates to True, result is True. However, if either
expression is Null, result is also Null).
5. CONCATENATION OPERATORS
Operator Description
& Concatenate (join two strings together)
+ Adds two numbers together
We can also place <script> tag within the <body> …</body> tags as follows.
<html>
<head>
<title>Untitled page</title>
</head>
<body>
<script type="text/vbscript">
// VBScript code here
</script>
</html>
Example:-
<html>
<body>
<script type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>
Empty It is the default value of a variable, that is to say the value of the variable before
initialiazation
Currency Contains a currency value ranging from -922 337 203 685 477.5808 to 922 337
203 685 477.5807
This is a sub-type suitable for large financial values
Long Contains a long integer whose value is between -2 147 483 648 to 2 147 483 647
Single Contains a float value ranging between -3,402823E38 and -1,401298E-45 for
negative values and between 1,401298E-45 and 3,402823E38 for the positive
values
Double Contains a float value, ranging between 1,79769313486232E308 and -
4,94065645841247E-324 for negative values and between 4,94065645841247E-
324 to 1,79769313486232E308 for positive values
Date / Time contains a date between 1th January 100 and 31 December 9999.
Creating variables in VBScript is most often referred to as "declaring" variables.we can declare
VBScript variables with the Dim, Public or the Private statement. Like this:
Dim x
Dim
carname
Now we have created two variables. The name of the variables are "x" and "carname".
we can also declare variables by using its name in a script. Like this:
carname="Volvo"
OPERATORS:- (JULY 2012) Refer Q.NO-6 (in 5-Marks)
12. Explain the execution of for… Next loop in VBScript
For...Next Loop:-
We can use the For...Next statement to run a block of code a specified number of times.
The For statement specifies the counter variable (i), and its start and end values. The Next statement
increases the counter variable (i) by one.
Syntax:-
For var_name = Start_value To End_value
// body of the loop
Next
Example:-
The following example causes a procedure called MyProc to execute 50 times. The For statement
specifies the counter variable x and its start and end values. The Next statement increments the
counter variable by 1.
Sub DoMyProc50Times()
Dim x
For x = 1To50
MyProc
Next
End Sub
13. What are the built in functions available in VBScript? Discuss them with examples.
A built in function that is built into an application and can be accessed by end-users
VBScript Built in functions are as follows:
1. Mathematical functions
2. Date and Time functions
3. String functions
1. MATHEMATICAL FUNCTIONS:-
Mathematical Functions help us to evaluate the mathematical and trigonometrical functions of a given
input number.
Syntax:-
variablename = Mathematical_function_Name(Expression)
Function Description
Int A Function, which returns the integer part of the given number
Fix A Function, which returns the integer part of the given number
Log A Function, which returns the natural logarithm of the given number. Negative numbers
disallowed
Oct A Function, which returns the Octal value of the given percentage
Hex A Function, which returns the Hexadecimal value of the given number
Rnd A Function, which returns a random number between 0 and 1
Sgn A Function, which returns a number corresponding to the sign of the specified number
Sqr A Function, which returns the square root of the given number. Negative numbers
disallowed
Abs A Function, which returns the absolute value of the given number
Exp A Function, which returns the value of e raised to the specified number
Sin A Function, which returns sine value of the given number
Cos A Function, which returns cosine value of the given number
Tan A Function, which returns tan value of the given number
Examples:
Abs Function
Returns the absolute value of a number.
Dim num OUTPUT: num=50.33
num=abs(-50.33)
msgbox num
Sin
Returns the sine value of a number
Dim num OUTPUT: num=0.5
num=sin(30)
msgbox num
2.DATE FUNCTIONS:-
Date functions helps the developers to convert date from one format to another or to express the date
value in the format that suits a specific condition.
Syntax:-
variablename = Date_function_Name(Expression)
Function Description
Date A Function, which returns the current system date
CDate A Function, which converts a given input to Date
DateAdd A Function, which returns a date to which a specified time interval has been
added
DateDiff A Function, which returns the difference between two time period
DatePart A Function, which returns a specified part of the given input date value
DateSerial A Function, which returns a valid date for the given year,month and date
FormatDateTime A Function, which formats the date based on the supplied parameters
IsDate A Function, which returns a Boolean Value whether or not the supplied
parameter is a date
Day A Function, which returns an integer between 1 and 31 that represents the day
of the specified Date
Month A Function, which returns an integer between 1 and 12 that represents the
month of the specified Date
Year A Function, which returns an integer that represents the year of the specified
Date
MonthName A Function, which returns Name of the particular month for the specified date
WeekDay A Function, which returns an integer(1 to 7) that represents the day of the
week for the specified day.
WeekDayName A Function, which returns the weekday name for the specified day.
Examples:
Date Function- It returns current system Date
Dim myDate OUTPUT: 17-03-2018
myDate=Date
msgbox myDate
IsDate- It checks weather the given value is Date type or not
Examples:
1. Dim myDate,x OUTPUT: False
myDate=100
x=IsDate(myDate)
msgbox x
Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("yyyy", Date1, Date2)
Msgbox x 'Differnce in Years
Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("q", Date1, Date2)
Msgbox x 'Differnce in Quarters
Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("m", Date1, Date2)
Msgbox x 'Differnce in Months
Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("w", Date1, Date2)
Msgbox x 'Differnce in weeks
Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("d", Date1, Date2)
Msgbox x 'Differnce in days
2. STRING FUNCTIONS:-
String functions helps the developers to work with the strings effectively. Below are string methods
supported in VBScript
Syntax:-
variablename = String_function_Name(Expression)
Function Description
InStr Returns the first occurrence of the specified substring. Search happens from left
to right.
InstrRev Returns the first occurrence of the specified substring. Search happens from
Right to Left.
Lcase Returns the lower case of the specified string.
Ucase Returns the Upper case of the specified string.
Left Returns a specific number of characters from the left side of the string.
Right Returns a specific number of characters from the Right side of the string.
Mid Returns a specific number of characters from a string based on the specified
parameters.
Ltrim Returns a string after removing the spaces on the left side of the specified string.
Rtrim Returns a string after removing the spaces on the right side of the specified
string.
Trim Returns a string value after removing both leading and trailing blank spaces.
String Returns a String with a specified character the specified number of times.
StrReverse Returns a String after reversing the sequece of the characters of the given string.
Parameter Description
red Required. A number from 0 to 255, inclusive, representing the red component of the
color
green Required. A number from 0 to 255, inclusive, representing the green component of the
color
blue Required. A number from 0 to 255, inclusive, representing the blue component of the
color
Example:
<%response.write(rgb(255,0,0))%>
Syntax
The syntax of a While..Wend loop in VBScript is:
While condition(s)
[statements 1]
[statements 2]
...
[statements n]
Wend
15. Explain VBScript in detail (JULY 2012)
VBScript:-
Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight and active scripting
language developed by Microsoft that is modelled on Visual Basic.
VBScript is an interpreted script language from Microsoft that is a subset of its Visual
Basic programming language designed for interpretation by Web browsers
VBScript is a propriety client side scripting language by Microsoft, supported by Internet Explorer.
It is widely used in enterprises.
Nowadays, VBScript is the primary scripting language for Quick Test Professional (QTP), which is
a test automation tool.
Adding VBScript code into HTML:-
To add VBScript code to an HTML page, enclose the script within a pair of <SCRIPT> tags, using
either the TYPE attribute or the LANGUAGE attribute to specify the scripting language.
You can place VBScript code blocks anywhere on an HTML page. In fact, it is a good practice to
put all general-purpose scripting code (that is, script that is not tied to a particular form control) in
the HEAD section.
This ensures that script will already have been read and decoded before it is called from the body of
the HTML page.
Syntax:-
<html>
<head>
<script type="text/vbscript">
// VBScript code here
</script>
</head>
</html>
We can also place <script> tag within the <body> …</body> tags as follows.
<html>
<head>
<title>Untitled page</title>
</head>
<body>
<script type="text/vbscript">
// VBScript code here
</script></html>
Example:-
<html>
<body>
<script type="text/vbscript">
document.write("Hello World.!")
</script>
</body>
</html>
OUTPUT:-
Hello World.!
16. What are the String functions in VBScript (JULY 2012,APR.2014)
Refer Q.NO-13(in 5-Marks)
10 MARKS
1. Discuss the string functions in VBScript with examples (NOV. 2014)
Refer Q.NO-13(in 5-Marks)
2. Mention the salient features of VB Script (APR. 2013)
Features of VBScript:-
VBScript is a lightweight scripting language, which has a lightning fast interpreter.
VBScript, for the most part, is case insensitive. It has a very simple syntax, easy to learn and to
implement.
Unlike C++ or Java, VBScript is an object-based scripting language and NOT an Object-Oriented
Programming language.
It uses Component Object Model (COM) in order to access the elements of the environment in
which it is executing.
Successful execution of VBScript can happen only if it is executed in Host Environment such as
Internet Explorer (IE), Internet Information Services (IIS) and Windows Scripting Host (WSH)
VBScript is also used for Network Administration, System Administration and for UFT Test
Automation.
If we already know Visual Basic (VB) or Visual Basic for Applications (VBA), VBScript will be
very familiar.
The basic concepts of VBScript are common to most programming languages.
VBScript talks to host applications using Windows Script. With Windows Script, browsers and other
host applications do not require special integration code for each scripting component.
ERR OBJECT:-
The Err object holds information about the last runtime error that occured. It is not necessary to create
an instance of this object; it is intrinsic to VBScript. Its default property is Number, which contains an integer
representing a VBScript error number or an ActiveX control Status Code (SCODE) number.
This value is automatically generated when an error occurs and is reset to zero (no error) after an On
Error Resume Next statement or after using the Clear method.
Examples:
<%
dim numerr, abouterr
On Error Resume Next
Err.Raise 6
numerr = Err.number
abouterr = Err.description
If numerr<> 0 Then
Response.Write "An Error has occured! Error number " numerr " of the type '" abouterr "'."
End If
%>
Output:
"An Error has occured! Error number 6 of the type 'Overflow'."
Explanation:
This code checks the value of the Number property and, if it contains a value other than zero, displays
the details in the browser.
PROPERTIES:
1. Description
Syntax: object. Description [ =string]
This property returns or sets a string containing a brief textual description of an error.
2. HelpContext
Syntax: object.HelpContext[ =contextID]
This property is used to set or return a context ID for a Help topic specified with the HelpFile property.
3. HelpFile
Syntax: object. HelpFile[ =contextID]
This property is used to get or define the path to a Help file.
4. Number
Syntax: object.Number[ =errnumber]
This property is used to retrieve or set the value that relates to a specific runtime error.
5. Source
Syntax: object. Source [ =string]
This property lets us determine the object or application that caused an error, and returns a string that
contains its Class name or programmatic ID.
METHODS:-
1. Clear
Syntax: object.Clear
This method is used to clear teh settings of the Error object.
2. Raise
Syntax: object.Raise(number[, source, description, helpfile, helpcontext])
This method is used to generate a VBScript runtime error.
Example
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","Clear"
</script>
</body>
</html>
1. EXISTS METHOD:-
Exist Method helps the user to check whether or not the Key Value pair exists.
object.Exists(key)
where,
Object - a Mandatory Parameter. This represents the name of the Dictionary Object.
Key - a Mandatory Parameter. This represents the value of the Dictionary Object.
Example
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dim d,msg'Create some variables.
Set d =CreateObject("Scripting.Dictionary")
d.Add"a","Apple"'Add some keys and items.
d.Add"b","BlueTooth"
d.Add"c","C++"
Ifd.Exists("c")Then
msgbox"Specified key exists."
Else
msgbox"Specified key doesn't exist."
EndIf
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in
a message box.
OUTPUT:-
Specified key exists.
2. ITEMS METHOD:-
Items Method helps us to get the values stored in the key value pair of the data dictionary object.
object.Items()
where,
Object- a Mandatory Parameter. This represents the name of the Dictionary Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.items
msgboxa(0)
msgboxa(2)
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in
a message box.
OUTPUT:-
Apple
C++
3. KEYS METHOD:-
object.Keys()
where,
Object- a Mandatory Parameter. This represents the name of the Dictionary Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.Keys
msgboxa(0)
msgboxa(2)
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in a
message box.
OUTPUT:-
a
c
4. REMOVE METHOD:-
object.Remove(key)
where,
Object- a Mandatory Parameter. This represents the name of the Dictionary Object.
Key - a Mandatory Parameter. This represents the key value pair that needs to be removed from the Dictionary
Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.Keys
msgboxa(0)
msgboxa(2)
obj_datadict.remove("b")'The key value pair of "b" is removed'
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in
a message box.
OUTPUT:-
a
c
5. REMOVE ALL METHOD:-
object.RemoveAll()
where,
Object - a Mandatory Parameter. This represents the name of the Dictionary Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.Keys
msgboxa(0)
msgboxa(2)
obj_datadict.removeall
</script>
</body>
</html>
5. Explain how anchor tags are used in HTML (NOV.2014)
An anchor tag is an HTML tag. It is used to define the beginning and end of a hypertext link. It contains
visible words within a text that can be clicked and the URL of the link's target. Search engines use this HTML
tag in order to determine the subject matter of the linked target.
Building a Hyperlink with an Anchor Tag:-
<a href="http://www.beispiel.com">My sample page </a>
Href is short for hypertext reference. This attribute defines the target address of the document, which is
to be linked to (http://www.google.com). The “=” sign is the connection of the attribute with the attribute value,
whereby “href” is the attribute and “ http://www.google.com ” is the attribute value. There is an apostrophe
before and after the attribute value. The defined phrase “Google Home” is called anchor text or link text. This
part is clickable in the text. An anchor text is ideally informative and relevant to the landing page.
2. Name attribute:-
The name attribute of the anchor tag can be used to enable users to “jump” to a specific point on a page
(jump marker, anchor). This is especially useful with large pages or subdivisions.
The HTML code looks like this:
<a name="to top"></a> or
<a name="Content">Content</a>
In the first code sample, you link from the bottom of a page back to the beginning. So users can quickly
get to the top of that page without having to scroll for a long time. In the second example, users can get direct
access to the page, for example, by linking to a subdivision point. By clicking, users are guided via name
attribute directly to the subject.
<a href="#Content">Content</a>
By simply setting a hash tag (#) at the anchor name the browser can identify a jump within the page.
3. Target attribute:-
The target attribute specifies how the destination page or the target document should be opened.
“target=” _ blank “ is used for opening of the target page in a new window. This is the usual option when using
target attributes for linking to other pages.
<a href="http://www.mypage.com" target="_blank">Linktext</a>
Function myfunction()
some statements
myfunction=some value
End Function
(Or)
Function myfunction(argument1,argument2)
some statements
myfunction=some value
End Function
Calling a Function:-
This simple function procedures is called to calculate the sum of two arguments:
Example:-
Function myfunction(a,b)
myfunction=a+b
End Function
response.write(myfunction(5,9))
The function "myfunction" will return the sum of argument "a" and argument "b". In this case 14.
When we call a procedure you can use the Call statement, like this:
Call MyProc(argument)
Or, you can omit the Call statement, like this: MyProc argument
VBScript Built in functions are as follows:
Mathematical functions
Date and Time functions
String functions
Refer Q.NO-13(in 5-Marks)
UNIT-II
2 MARKS
1. Write down the JavaScript comments.(APR.2016,NOV.2014)
Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
2. How to use conditional expression in JavaScript?(APR.2006)
The conditional (ternary) operator is the only JavaScript operator that takes three operands.
This operator is frequently used as a shortcut for the if statement.
Syntax:-
variablename = (condition) ? value1:value2
Example:-
var voteable = (age < 18) ? "Too young":"Old enough";
3. Explain the break statement in Java Script.(APR.2006)
Break statement will break the loop and continue executing the code that follows after the loop.
Example:-
for(i=0;i<=5;i++)
{
if(i==3)
{
break
}document.write(+i)
}
4. How to define and use function in Java Script?(APR.2008)
Defining function
Function function_name(parameter1,parameter2,….)
+ Addition
* Multiplication
/ Division
% Modulus
Arrays are JavaScript objects that are capable of storing a sequence of values. These values are
stored in indexed locations within the array.
ENTER A NUMBER
prompt X
Enter the number OK CANCEL
5 Ok
Primitive complex
Number Array
Boolean Objects
String
Null
24. How an array is defined in JavaScript?
Arrayname=new Array(array length)
Eg.Flower=new Array(5)
25. List any three commands in JavaScript with example.
Var,break,continue.
26. Define: NULL value.
The null value is a unique value representing no value or no object. It implies no object, or null string ,
no valid Boolean value, no number and no array object.
27. Explain the comparison operator in Java Script.
Comparison operators are used to compare two values. The comparison operators supported by
JavaScript are:
OPERATOR DESCRIPTION
== Equal
!= Not Equal
for while
31. Name any two user defined functions in JavaScript.(NOV.2013)
User defined function first needs to be declared and coded and that can be invoked by calling it using the
name given when it was declared. Eg.functionclass, function mark.
32. How to create variables in JavaScript?
Variables can be created that can hold any type of data. Variables can be declared using varcommand.
Syntax: var<variable name>=value;
JAVASCRIPT SYNTAX:-
SYNTAX:-
<SCRIPT LANGUAGE=”JavaScript”>
</SCRIPT>
The browser is given this information using the HTML tags <SCRIPT>….</SCRIPT>.
The <SCRIPT> tag marks the beginning of a snippet of scripting code.
The paired </SCRIPT> tag marks the end of a snippet of scripting code.
Like most other HTML tags, the <SCRIPT> tag takes in an optional attribute, as listed below.
Attributes Description
LOOPING:-
for(expression1;condition;expression2)
}
While Loop:-
Syntax:-
while (condition)
// JavaScript commands
<head>
</Script>
</head>
</html>
The <HEAD> tag makes an ideal place to create JavaScript variables and constants and so on.
This is because the head of an HTML document is always processed before the body.
Placing JavaScript memory variables, constants and user defined functions in the HEAD section of
the document will cause them to be defined before being used.
This is important because any attempt to use a variable before it is defined, results in an error.
We can also place <SCRIPT> tag within the <BODY>….</BODY> tags of an HTML document as
follows:
<html>
<head>
</head>
<body>
</Script>
</body>
</html>
Example :-
<html>
<body>
</Script>
</body>
</html>
OUTPUT:-
Hello World.!
4. How do you differentiate between local variables and global variables in JavaScript.(NOV.2012)
1. A variable that is declared inside a function 1. A variable that is declared outside of a function
definition is called local variable definition is called a global variable
2.It has scope to that function only 2. It’s scope is throughout your program means its value is
accessible and modifiable throughout your program.
3. Local variables are deleted when the 3. Global variables are deleted when you close the browser
function is completed window (or tab), but remain available to new pages loaded
into the same window.
4. Accessed only by the statements, inside 4. Accessed by any statement in the entire program.
function in which they are declared
JavaScript Language supports numeric, Boolean and string data. Apart from the above three types, object is
another important data type supported. As an open standard the null data and undefined data types are also
supported.
1. NUMBERS:-
The integer and floating point numeric data are called numbers. A number can be positive, negative or
zero.
Integers can be represented in decimal, octal and hexadecimal form. The octal integer begins with a zero
and hexadecimal integer begins with Ox or oX.
Floating point numbers can be represented either in decimal form or exponent form. The following are
some valid floating point numbers.
0.78
-10.2
2. BOOLEAN:-
JavaScript considers true or false values as Boolean values. In comparison 0 is consider as false and
any non-zero value as true. JavaScript automatically converts the Boolean values true and false into 1 and 0
when they are used in numerical expressions. Values 1 and 0 are not considered Boolean values in
JavaScript.
3. STRING:-
JavaScript provides built-in support for strings. A string is a sequence of zero or more characters that
are enclosed by double(“) or single(‘) quotes.
For example : “Rahul”, ’24, Sanjay Nagar, Bangalore’
4. OBJECT:-
As Javascript is an object oriented language, it is possible to define an object of a class. For example an
object of an employee class can be created using new operator as follows:
X=new employee(“Rajasekar”,45);
5. NULL AND UNDEFINED DATA TYPES:
A null value is one that has no value. A value that is undefined is a value held by a variable after it has
been created. It identifies a null, empty or nonexistent reference. It is used to set a variable to an initial value
that is different from other valid dates.
An array must be declared before it is used. An array can be declared using any one of the following
techniques.
arrayName=new Array()
In the first example, the array size is explicitly specified. Hence this array will hold a pre-determined set
of values.
The second example creates an array of the size 0.
NOTE: JavaScript automatically extends the length of any array when new array elements are initialized.
Example;-
An operator is used to transform one or more values into a single resultant value. The values which the
operator is applied are referred to as operands.
1. Arithmetic Operators
2. Logical Operators
3. Comparison Operators
4. String Operators
5. Assignment Operators
7. Special Operators
1. ARITHMETIC OPERATORS:-
Arithmetic operators are the most familiar operators because they are used every day to solve common
math calculations. The arithmetic operators that JavaScript supports are:
OPERATOR DESCRIPTION
+ Addition
* Multiplication
/ Division
% Modulus
2. LOGICAL OPERATORS:-
Logical operators are used to perform Boolean operators on Boolean operands AND, OR, NOT. The
logical operators that supported by JavaScript are:
OPERATOR DESCRIPTION
&& Logical AND
|| Logical OR
! Logical NOT
3. COMPARISON OPERATORS:-
Comparison operators are used to compare two values. The comparison operators supported by
JavaScript are:
OPERATOR DESCRIPTION
== Equal
!= Not Equal
4. STRING OPERATORS:-
String operators are those operators that are used to perform operations on strings. Currently JavaScript
supports only the string concatenation (+) operator. This operator is used to join two strings. For example,
“pq”+”ab” produces “pqab”.
5. ASSIGNMENT OPERATORS:-
The assignment operator is used to update the value of a variable. Some assignment operators are
combined with other operators to perform a computation on the value contained in a variable and then
update the variable with the new value. Some of the assignment operators supported by JavaScript are:
OPERATOR DESCRIPTION
= Sets the variable on the left of the = operator to the value of the
expression on its right.
JavaScript supports the conditional expression operator. They are ? and : The conditional expression
operator is ternary operator since it takes three operands, a condition to be evaluated and two alternative
values to be returned based on the truth or falsity of the condition
Syntax:-
Condition? Value1:Value2
The condition expressed must return a value true or false. If the condition is true, value1 is the result of the
expression, otherwise value2 is the result of the expression.
JavaScript supports the conditional expression operator. They are ? and : The conditional expression
operator is ternary operator since it takes three operands, a condition to be evaluated and two alternative values
to be returned based on the truth or falsity of the condition
We have a person object that consists of a name, age, and driver property.
var person = {
name: 'tony',
age: 20,
driver: null
};
We want to test if the age of our person is greater than or equal to 16. If this is true, they’re old enough to drive
and driver should say 'Yes'. If this is not true, driver should be set to 'No'.
if (person.age>= 16)
person.driver = 'Yes';
else
person.driver = 'No';
But what if I told you we could do the same exact thing in just one line of code? Well, here it is:
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.
Syntax
if (condition)
}
Example
The for loop is often the tool you will use when you want to create a loop.
Syntax:-
code to be executed
A JavaScript function is defined with the function keyword, followed by a name, followed by
parentheses ().
Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
The parentheses may include parameter names separated by commas:(parameter1, parameter2, ...)
The code to be executed, by the function, is placed inside curly brackets: {}
Function parameters are listed inside the parentheses () in the function definition.
Function arguments are the values received by the function when it is invoked.
Inside the function, the arguments (the parameters) behave as local variables.
A Function is much the same as a Procedure or a Subroutine, in other programming languages.
Example
10 MARKS
1. Elaborate the control structures in JavaScript with an example.(APR. 2013)
Control Structure:-
Control structure actually controls the flow of execution of a program. Following are the several control
structure supported by JavaScript.
1. if … else
2. switch case
3. do while loop
4. while loop
5. for loop
1. The if Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.
Syntax
if (condition)
}
Example
Good day
2. Switch case
The basic syntax of the switch statement is to give an expression to evaluate and several different
statements to execute based on the value of the expression. The interpreter checks each case against the
value of the expression until a match is found. If nothing matches, a default condition will be used.
Syntax:-
switch (expression)
break;
break;
...
break;
default: statement(s)
Example
<script type="text/javascript">
<!--
var grade='A';
switch (grade)
break;
break;
break;
break;
break;
//-->
</script>
3. While loop:-
The purpose of a while loop is to execute a statement or code block repeatedly as long as expression is
true. Once expression becomes false, the loop will be exited.
Syntax
while (expression)
Example
<script type="text/javascript">
<!--
var count = 0;
document.write("Loop stopped!");
//-->
</script>
OUTPUT:-
Starting Loop
Current Count : 0
Current Count : 1
Current Count : 2
Current Count : 3
Current Count : 4
Current Count : 5
Current Count : 6
Current Count : 7
Current Count : 8
Current Count : 9
Loop stopped!
4. Do while loop:-
The do...while loop is similar to the while loop except that the condition check happens at the end of the
loop. This means that the loop will always be executed at least once, even if the condition is false.
Syntax
do
Statement(s) to be executed;
} while (expression);
Example
<script type="text/javascript">
var count = 0;
do{
count++;
document.write("Loop stopped!");
</script>
OUTPUT:-
Starting Loop
Current Count : 0
Loop stopped!
The for loop is often the tool you will use when you want to create a loop.
Example:-
JavaScript Language supports numeric, Boolean and string data. Apart from the above three types,
object is another important data type supported. As an open standard the null data and undefined data types
are also supported.
1. NUMBERS:-
The integer and floating point numeric data are called numbers. A number can be positive, negative or
zero.
Integers can be represented in decimal, octal and hexadecimal form. The octal integer begins with a zero
and hexadecimal integer begins with Ox or oX.
Floating point numbers can be represented either in decimal form or exponent form. The following are
some valid floating point numbers.
0.78
-10.2
2. BOOLEAN:-
JavaScript considers true or false values as Boolean values. In comparison 0 is consider as false and
any non-zero value as true. JavaScript automatically converts the Boolean values true and false into 1 and 0
when they are used in numerical expressions. Values 1 and 0 are not considered Boolean values in
JavaScript.
3. STRING:-
JavaScript provides built-in support for strings. A string is a sequence of zero or more characters that
are enclosed by double(“) or single(‘) quotes.
For example : “Rahul”, ’24, Sanjay Nagar, Bangalore’
4. OBJECT:-
As Javascript is an object oriented language, it is possible to define an object of a class. For example an
object of an employee class can be created using new operator as follows:
X=new employee(“Rajasekar”,45);
ADVANTAGES:-
Expressions:
Arithmetic: evaluates to a number, for example 3.14159. (Generally uses arithmetic operators.)
String: evaluates to a character string, for example, "Fred" or "234". (Generally uses string operators.)
Logical: evaluates to true or false. (Often involves logical operators.)
Primary expressions: Basic keywords and general expressions in JavaScript.
Left-hand-side expressions: Left values are the destination of an assignment.
JAVASCRIPT STRUCTURE:-
<SCRIPT LANGUAGE=”JavaScript”>
</SCRIPT>
The browser is given this information using the HTML tags <SCRIPT>….</SCRIPT>.
The <SCRIPT> tag marks the beginning of a snippet of scripting code.
The paired </SCRIPT> tag marks the end of a snippet of scripting code.
Like most other HTML tags, the <SCRIPT> tag takes in an optional attribute, as listed below.
Attributes Description
ADVANTAGES:-
JavaScript provides the ability to pickup user input or display small amount of text to the user by the
dialog boxes. These dialog boxes appear as second windows and their content depends on the information
provided by the user.
The simplest way to direct small amounts of textual output to a browser’s window is to use an alert
dialog box.
The JavaScript alert() method takes a string as an argument and displays an alert dialog box in the
browser window when invoked by appropriate JavaScript.
The alert dialog box displays the string passed to the alert() method, as well as an OK button .
The alert dialog box can be used to display a cautionary message or display some information. For
instance:
1. A message is displayed to the user when incorrect information is keyed in a form.
2. An invalid result is the output of a calculation
3. A warning that a service is not available on a given date/time.
Syntax:-
alert(“<Message>”);
Example:-
alert(“Click OK to Continue”);
Example Program:-
<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT language=”JavaScript”>
alert(“Welcome to my website!”);
</SCRIPT>
</BODY>
</HTML>
JavaScript provides a prompt dialog box for this. The prompt() method instantiates the prompt dialog
box which displays a specified message.
In addition, the prompt dialog box also provides a single data entry field, which accepts user input.
Thus, a prompt dialog box:
1. Displays a predefined message
2. Displays a textbox and accepts user input.
3. Displays the OK and the Cancel button.
When the prompt() method is used to instantiate and use a dialog box the method requires two blocks of
information:
1. A message to be displayed as a prompt to the user.
2. Any message to be displayed in the textbox (this is optional)
Syntax:-
prompt(“<Message>”,”<Default value>”);
Example:-
Example Program:-
<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT language=”JavaScript”>
document.write(prompt(“Enter your name:”,”Name”));
document.write(“ Welcome to my homepage!”);
</SCRIPT>
</BODY>
</HTML>
JavaScript provides a third type of dialog box called the confirm dialog box.
As the name suggests, this dialog box serves as a technique for confirming user action.
The confirm dialog box displays the following information:
1. A pre-defined message
2. OK and Cancel Button
Display of a confirm dialog box thus requires only one block of information: A pre-defined message to
be displayed.
Syntax:-
confirm(“<Message>”);
Example:-
Example Program:-
<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT language=”JavaScript”>
var txt;
var r = confirm("Press a button!");
if (r == true)
{
txt = "You pressed OK!";
}
else
{
txt = "You pressed Cancel!";
}
</SCRIPT>
</BODY>
</HTML>
The above program displays a confirmation box, and output what the user clicked.
Arrays are JavaScript objects that are capable of storing a sequence of values. These values are stored in
indexed locations within the array.
The array element index starts with 0. Hence the last array element index number is one less that the
length of the array.
An array must be declared before it is used. An array can be declared using any one of the following
techniques.
arrayName=new Array()
In the first example, the array size is explicitly specified. Hence this array will hold a pre-determined set
of values.
The second example creates an array of the size 0.
JavaScript automatically extends the length of any array when new array elements are initialized.
Example;-
Even if an array is initially created of a fixed length it may still be extended by referencing elements that
are outside the current size of the array. This is done with the same manner as with zero-length arrays.
Example Program:-
You can create an array in javascript as follows (in this example you can see an entire .html file; later on
we'll just look at the javascript part)
<html>
<script language="javascript">
// Empty array
alert(fruits[1]);
</script></head>
<body>
</body>
</html>
Constructor Functions:-
Constructor functions are the equivalent of classes in many programming languages. Sometimes people
will refer to them as as reference types, classes, data types, or simply constructors.
If you aren’t familiar with classes, they are a construct that allows you to specify some properties and
behaviors (functions), and multiple objects can be created with those properties and behaviors.
A common analogy you’ll often hear is, a class is to a blueprint as an object is to a house. Multiple
houses can be created from a single blueprint, as multiple objects can be created from a class.
function Person(name,position)
{
this.name=name;
this.position=position;
There is really nothing special about this function except that the function name starts with a
capital letter.
This isn’t mandatory, but it is popular convention so that other developers know to invoke it as a
constructor function.
When a constructor function is invoked with the new keyword, this refers to the object that is
being constructed. Note, if a constructor is invoked without the new keyword, this will point to the
global object, which is the window object in the browser. This will end up creating properties on the
window object (also known as global variables), which is not a recommended practice.
Methods:-
function Person(name)
this.name=name;
this.hi=function()
};
In this example, the hi property is assigned a function. When it is invoked off of a Person object, the
keyword this will correspond to the newly constructed Person object.
1. Arithmetic Operators
2. Logical Operators
3. Comparison Operators
4. String Operators
5. Assignment Operators
7. Special Operators
1. ARITHMETIC OPERATORS:-
Arithmetic operators are the most familiar operators because they are used every day to solve common math
calculations. The arithmetic operators that JavaScript supports are:
OPERATOR DESCRIPTION
+ Addition
* Multiplication
/ Division
% Modulus
2. LOGICAL OPERATORS:-
Logical operators are used to perform Boolean operators on Boolean operands AND, OR, NOT. The
logical operators that supported by JavaScript are:
OPERATOR DESCRIPTION
|| Logical OR
! Logical NOT
3. COMPARISON OPERATORS:-
Comparison operators are used to compare two values. The comparison operators supported by
JavaScript are:
OPERATOR DESCRIPTION
== Equal
!= Not Equal
4. STRING OPERATORS:-
String operators are those operators that are used to perform operations on strings. Currently JavaScript
supports only the string concatenation (+) operator. This operator is used to join two strings. For
example, “pq”+”ab” produces “pqab”.
5. ASSIGNMENT OPERATORS:-
The assignment operator is used to update the value of a variable. Some assignment operators are
combined with other operators to perform a computation on the value contained in a variable and then
update the variable with the new value. Some of the assignment operators supported by JavaScript are:
OPERATOR DESCRIPTION
JavaScript supports the conditional expression operator. They are ? and : The conditional expression
operator is ternary operator since it takes three operands, a condition to be evaluated and two alternative
values to be returned based on the truth or falsity of the condition
Syntax
Condition? Value1:Value2
The condition expressed must return a value true or false. If the condition is true, value1 is the result of
the expression, otherwise value2 is the result of the expression.
EXPRESSIONS:-
UNIT-III
2 MARKS
1. Define: cookies? (NOV.2013, NOV. 2014, JULY 2012, JULY 2014,JULY 2016)
A Cookie is a small text file that the browser creates and stores on the hard drive of your machine.
Cookie is just one or more pieces of information stored as text string.
Once a cookie has been stored, the information in the cookie will be sent back to the web server
each time your browser request data
(e.g. web pages and multimedia files)from the server
syntax :
set cookie = "name=value; expires=date; path=path; domain=domain; secure";
The Navigator object is designed to contain information about the version of Netscape Navigator
which is being used.
It contains information about different aspects of the browser.
Language Objects – Objects provided by the language and are not dependent on other objects.
Navigator Objects-Objects provided by the client browser.These objects are all sub objects to the
navigator object.
Document Object – The JavaScript Document object is the container for all HTML and BODY
objects associated within the HTML tags of an HTML document.
Form object - form object is a Browser object of JavaScript used to access an HTML form. If a
user wants to access all forms within a document then he can use the forms array.
Window Object - The JavaScript Window Object is the highest level JavaScript object which
corresponds to the web browser window.
5-MARKS
Example:
Screen Object
The anchors collection returns an array of all the anchors in the current document.
Syntax
document.anchors[].property
Example
<html>
<body>
<a name=" java ">java</a><br />
<a name="c++">C++</a><br />
<script type="javascript">
document.write(document.anchors.length);</script></p></body>
</html>
Forms give life to static pages by providing an interface users can interact with through controls.
You can only place button,text, or other UI objects within the confines of a form.
The form object is your means of inter-acting with this HTML element in your scripts.
i. Button objects
ii. Select object
iii. Checkbox object
iv. Radio object
v. Text object
vi. Textarea object
vii. Password object
Syntax
[TARGET=”windowName”] [onSubmit=”methosName”]>
</form>
Example
<HTML>
<HEAD><Title>Form example</Title></HEAD>
<Body>
<Br>
<Input Type=Submit>
</FORM>
</BODY>
</HTML>
Action
Encoding
Length
Method
Name
Target
Button checkbox
fileUpload
hidden
password
radio
reset
select
submit
text
textarea
10-MARKS
1. Explain the following Objects. (APR.2014, JULY 2014)
a) Browser Object(APR. 2013,APR. 2016)
b) Navigator Object
Ans: a) Browser object- REFER Q.NO.1(10-MARKS) – WINDOW OBJECT, REFER .NO.1(5-MARKS) –
SCREEN OBJECT
b) Navigator Object
Property Description
UserAgent Returns the user-agent header sent by the browser to the serve
The Navigator object is designed to contain information about the version of Netscape Navigator which is being
used. However, it can also be used with Internet Explorer. All of its properties, which are read-only, contain
information about different aspects of the browser.
Navigator Syntax
navigator.appCodeName
navigator.appName
navigator.appVersion
navigator.cookieEnabled
navigator.platform
navigator.userAgent
Example
<html> <body>
<script type="javascript">
document.write("br />");
</script>
</body> </html>
2. Describe the document Object model in javascript? (APR. 2013, APR. 2016)
JavaScript handles the HTML documents and the related objects such as windows, forms and screen in a
specified hierarchy.
This hierarchy is called the Document Object Model(DOM) are directly related to the browser.
The properties of the objects covered in the DOM get their values supplied by the browser.
Each HTML document loaded into a browser window becomes a Document object.
The Document object provides access to all HTML elements in a page, from within a script.
The Document object is also part of the Window object, and can be accessed through the
window.document property.
Collection Description
anchors[] Returns an array of all the anchors in the document
forms[] Returns an array of all the forms in the document
images[] Returns an array of all the images in the document
links[] Returns an array of all the links in the document
Anchors
The anchors collection returns an array of all the anchors in the current document.
Syntax:
document.anchors[].property
Example
<html>
<body>
<a name=" java ">java</a><br />
<a name="c++">C++</a><br />
<script type="text/javascript">
document.write(document.anchors.length);
</script>
</p>
</body>
</html>
forms
The forms collection returns an array of all the forms in the current document
Syntax:
document.forms[].property
Example
<html>
<body>
<form name="Form1">
</form>
<form name="Form2">
</form>
<p>Number of forms:
<script type="javascript">
document.write(document.forms.length);
</script>
</p>
</body>
</html>
images
The images collection returns an array of all the images in the current document.
Syntax:
document.images[].property
Example:
<html>
<body>
<img border="0" src="a.jpg" width="150" height="113" />
<img border="0" src="b.jpg" width="152" height="128" />
<p>Number of images:
<script type="javascript">
document.write(document.images.length);
</script>
</p>
</body>
</html>
Links
The links collection returns an array of all the links in the current document. The links collection counts <a
href=""> tags and <area> tags.
Syntax
document.links[].property
Example
<html>
<body>
<a href="images.html">
Images</a>
<p>Number of areas/links:
<script type="javascript">
document.write(document.links.length);
</script>
</p>
</body>
</html>
Methods Description
Properties:
The string object has only one property:
Property Description
Methods:
Methods Description
c. Date Object:
The Date object enables JavaScript Programmers to create an object that contains information about a
particular date and provides a set of methods to work with that information.
To create an instance of the data object; use new keyword
Syntax:
var my_date=new Date (<parameters>);
Methods:
Method Description
Forms give life to static pages by providing an interface users can interact with through controls.
we can only place button, text, or other UI objects within the confines of a form.
The form object is your means of inter-acting with this HTML element in your scripts.
viii. Button objects
ix. Select object
x. Checkbox object
xi. Radio object
xii. Text object
xiii. Textarea object
xiv. Password object
Syntax
</form>
Action
Encoding
Length
Method
Name
Target
Button checkbox
fileUpload
hidden
password
radio
reset
select
submit
text
textarea
elements[]
Action:
This property is a read or write property and its value is a string.
Elements[]:
It contains all fields and controls present in the form. The user can access any element associated with the form
by using the looping concept on the elements array.
Encoding:
This property is a read or write property and its value is a string. This property helps determine the way of
encoding the form data.
Length:
This denotes the length of the elements array associated with the form. method:
This property is a read or write property and its value is a string. This property helps determine the method by
which the form is submitted.
Name:
name property of form object denotes the form name.
Target:
This property denotes the name of the target window to which form it is to be submitted into.
Button:
The button property of form object denotes the button GUI control placed in the form.
Checkbox:
Checkbox property of form object denotes the checkbox field placed in the form.
Select:
Select property of form object denotes the selection list object placed in the form.
Submit:
Submit property of form object denotes the submit button field that is placed in the form.
Text:
Text property of form object denotes the text field placed in the form.
Textarea:
Textarea property of form object denotes the text area field placed in the form.
Example:
<HTML>
<HEAD><Title>Form example</Title></HEAD>
<Body>
<Input Type=Submit>
</FORM>
</BODY>
</HTML>
Window Object
The window object is the top-level object of the object hierarchy. Whenever an object method or property is
referenced in a script without the object name and dot prefix it is assumed by JavaScript to be a member of the
window object. This means, for example, that when calling the window alert() method to display an alert dialog
the window. Therefore the following method calls achieve the same thing:
window.alert(); or alert()
The JavaScript window object contains a number of properties that can be inspected and used in a script:
window.closed - Used when handling multiple windows, this property indicates whether a window has
been closed or not.
window.frames[] - If the window contains frames this array holds the array of frame objects (see
JavaScript Arrays details on accessing arrays).
window.name - Windows opened by a script must be given a name. This property contains the name of
the corresponding window object.
window.opener - When a window has been opened in a script contained in another window, this
property of the child window contains a reference window which opened it.
window.parent - When working with frames in a window this property contains a reference to the
window object that contains the frame.
window.screen - An object which contains information about the screen on which the window is
displays (properties contained in this object include height, width, availHeight, availWidth and
colorDepth).
A new browser window can be opened from a JavaScript script using the open() method of the window object.
The following provides an explanation of the arguments passed through to the open() method:
URL - Specifies the URL of the web page to be loaded into the new window. If no URL is specified a
blank window is loaded.
WindowName - Specifies the window name and is used to refer to the window.
features - A comma separated list of features that allow you to customize the appearance of the window.
Options are:
Setting Explanation
width Specifies the initial width of the browser client window (see innerWidth for size of content area)
height Specifies the initial height of the browser client window (see innerHeight for size of content area)
innerWidth Specifies the initial width of the window content area
innerHeight Specifies the initial height of the window content area
outerWidth Specifies the initial width of the navigator window
outerHeight Specifies the initial height of the navigator window
toolbar Specifies whether the window should contain the browser toolbar or not
status Specifies whether the window should contain the browser status bar or not
dependent Specifies whether the window should close in unison with its parent window
menubar Specifies whether the window should contain the browser menubar
The height, width and position features are set using numbers. The remaining feature options can be set using
true or false values (also yes, no and 1 and 0 can be used in place of true and false). An absent attribute is
considered to be false.
Example:
A window can be closed using the window object's close() method. The name of the window (specified in the
open() method) should be referenced when performing a close so that you are certain to close the correct
window.
Example:
The following code creates a new window and creates a pushbutton which, when clicked, closes the new
window:
</script>
<form action="null">
<input type="button" value="Close Window" onclick="newWindowObj.close()" />
</form>
It is also possible to close the window that opened the current window using the opener property of the current
window object:
window.opener.close()
This will close the window that opened the window in which the above script is run.
UNIT-IV
2 MARKS
1. What is meant by Event Handling? (NOV. 2014,APR.2014)
JavaScript’s response to one of the user initiated events is called event handling.
Example: JavaScript handle the event by calling a function that will perform some designated task, such
as to open a new window or bring a window into focus, perform a calculation, or submit a fill-out form.
ASP.NET uses an event-driven model of programming. This model of ASP.NET defines a sequence of
events that are fired during the life cycle of a web page.
Property: Description:
We can add individual radio button to your page one by one, using the RadioButton control.
RadioButton are grouped together using the GroupName property. Only one RadioButton control from
each group can be selected at a time.
We have two properties which we an work with the page object. They are
IsPostBack Property
IsValid Property
HtmlAnchor
HtmlTable
HtmlButton
HtmlForm
Repeater control displays data using user-defined layout. It just repeats the HTML and ASP.NET
controls that is placed inside a template block.
5 MARKS
8. Expain the following: (APR-2015)
a. Anchor
b. Table
c. Forms
d. Files
Property Description
Attributes Returns all attributes name and value pairs of the element
Disabled A Boolean value that indicates whether or not the control should be disabled.
Default is false.
InnerHtml Sets or returns the content between the opening and closing tags of the
HTML element
InnerText Sets or returns all text between the opening and closing tags of the HTML
element.
OnServerClick The name of the function to be executed when the link is clicked
Runat Specifies that the control is a server control. Must be set to “server”
Style Sets or returns the CSS properties that are applied to the control
Visible A Boolean value that indicates whether or not the control should be
visible
Property Description
Attributes - Returns all attributes name and value pairs of the element.
User can add only one form control for a web page
Property Description
Action - Contains a URL defining where to send the data in the form submitted
Attributes - Returns the attribute name and value pairs of the element
Visible - Specify a Boolean value whether the control should be visible or not
<html>
<head>
lblTime.Text=DateTime.Now.ToString()
End Sub
</script>
</head>
<body>
<p>Hello ther</p>
id =”lb_Time”/></p>
</body>
</html>
Save the file by using the Save option from the File menu. Enter the name of the title as aspsample.aspx in
the Filename textbox of the save as dialog box.
To access spsample. Aspx Web application, you first need to set a virtual directory for the aspsample.aspx
file. To set a virtual directory on the windows 2000 Server component on which you have developed the
ASP.NET application, you need to perform the following steps.
Click Start Programs Administrative ToolsInternet Services Manager to open the Internet
Information Services console.
Click the plus(+) sign next to the computer name to expand the web server tree.
Right-click the Default Web Site and select NewVirtual Directory option from the short-cut menu to open
the Virtual Directory Creation Wizard dialog box
Click the Next button to display the virtual directory alias page in the Virtual Directory Creation Wizard
dialog box. Specify the alias name as First in the Alias textbox.
Click the Next button to display the Web Site Content Director page in the Virtual Directory Creation
Wizard dialog box. Specify the directory path in which you have saved the First.aspx file in the Directory :
textbox.
Click the Next button to display the Access permissions page in the Virtual Directory Creation Wizard
dialog box. Ensure that Read and Run scripts permissions are selected in the Access permission page.
Click the Next button to display the last page of the Virtual Directory Creation Wizard dialog box. Click the
Finish button to close the Virtual Directory Creation Wizard dialog box.
After you create a virtual directory for an ASP.NET file, you can access the ASP.NET file by right-clicking
the file displayed in the right pane of the Internet Information Services and select the Browse option from
the short cut menu.
10. Describe the page structure of ASP.NET? (NOV. 2012, APR. 2012)
Directives
ASP.NET controls
Server-side comments
A directive controls how the page is compiled. It is marked by the tags, <%@ and %>. It can appear
anywhere in a page. But, normally it is placed at the top of a page.
Syntax:
<%@[Directive][Attribute=Value]%>
A code declaration block contains all the application logic for a page
Code declaration tags usually are placed in the <head> of your ASP.NET page
Used to execute code within the HTML or text content of the ASP.NET page
Types:
Inline code:
Begins with the characters <% and ends with the characters%>
Inline expressions
Begins with the characters <%= and end with the characters%>
</form>
Server-side comments:-
Used the <%-- beginning sequence and the --%> ending sequence
Advantage
Two techniques:
Give the physical path to the file on the server either as an absolute path starting form the drive letter or a
relative path to the current file.
Specify the file’s location from the absolute root of the site or from a relative path to the current page.
Literal text and HTML tags:- Build the static part of an ASP.NET page using HTML tags and literal text.
DataGrid control to display data on the web page. It is used to display data in scrollable grid. It requires
data source to populate data in the grid.
Property Description
Runat Specifies that the control is a server control. Must be set to “server”
Example: Default.aspx
<html>
<body>
</form>
</body></html>
Default.aspx.vb
Imports System.Data
Partial Class_Default
Inherits System.Web.UI.Page
table.Columns.Add(“ID”)
table.Columns.Add(“Name”)
table.Columns.Add(“Email”)
table.Rows.Add(“101”,”Elakkiyaa”,[email protected])
table.Rows.Add(“102”,”Sanju”,[email protected])
DataGrid1.DataSource=table
DataGrid1.DataBind()
End Sub
End Class
<%@Page Language=”VB”%>
The directive specifies instructions to the compiler. Two parameters are frequently used. This first is
Language, Language=VB. Here, it is set to VB, but it could be set to C# or any other .NET language. Next,
we set the Debug parameter to True,Debug=true.
The default for this parameter is False. If the parameter is set to True, the page will be compiled with debug
symbols. This means that when an error occurs on the page.
The default is True. When the parameter is set to True, the response is buffered; that is, the response is held
until complete. If the property is set to False buffering does not occur.
The Description parameter is ignored by the compiler. The parameter can be set to any string you like, but it
typically is set to a description of the page.
Two compiler options you can set are Option Explicit and Option Strict:
Explicit=True
Strict=True
Option Strict controls whether you allow variables to automatically be typed to different types as needed.
10 MARKS
1. Discuss the following in ASP.NET: (APR-2014)
The RadioButtonList control is used to create a group of radio button. Each selectable item in a
RadioButtonList control is defined by a ListItem element.
Property:
Property Description
Cell padding
The amount of pixels between the border and the contents of the
table cell
RepeatColumns The number of columns to use when displaying the radio button
group
Runat Specifies that the control is a server control. Must be set to “server”
TextAlign On which side of the radio button the text should appear
Example:
TextAlign=”Right” OnSelectedIndexChanged=”submit”
Runat=”sever”>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C#</asp:asp:ListItem>
</asp:RadioButtonList>
(b) CheckBoxList:-
The CheckBoxList control is used to create a multi-selection check box group. Each selectable item
in a CheckBoxList control is defined by a ListItem element.
Property:
Property Description
CellPadding The amount of pixels between the border and the contents of the
table cell
RepeatColumns The number of columns to use when displaying the radio button
group
Runat Specifies that the control is a server control. Must be set to “server”
TextAlign On which side of the check box the text should appear
Example:
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C#</asp:asp:ListItem>
</asp:CheckBoxList>
DropDownList:
The DropDownList control is used to create a drop-down list. Each selectable item in a DropDownList
control is defined by a ListItem element.
Property Description
Example:
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C#</asp:asp:ListItem>
</asp:DropDownList>
ListBox:
The ListBox control is used to create a single-or multi-selection drop-down list. Each selectable item
in a ListBox control is defined by a ListItem element.
Property:
Property Description
Example:
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C#</asp:asp:ListItem>
</asp:ListBox>
3. How web server controls are to be used in Asp.net? (NOV. 2012, APR. 2013, 2016)
Web Server controls are similar to HTML server controls. They are created on the server and builds
complex user interfaces with ease. All server controls must appear within a <form> tag, and the <form> tag
must contain the runat=”server” attribute.
Syntax:
<form runat=”server”>
</form>
Label:
Label way to display static text on your page is simply to add the text to the body of the page without
enclosing it in any tag.
Example:
Text Box:
The TextBox control is used to create on screen a box in which the user can type or read standard text.
This web control can be set to display a standard HTML text input field, an HTML password field, or an
HTML text area, using the TextMode property.
Property Description
Tab Index Returns/sets the tab order of a control within the form
Example:
<p>Username:
Button:
The Button control renders the same form submit button that’s rendered by the HTML <input
type=”Submit”> tag. When a button is clicked, the form containing the button is submitted to the
server for processing, and both click and command events are raised.
Example:
Image:
An Image control places on the page an image that can be accessed dynamically from code; it
equates to the <img> tag in HTML.
Example:
ImageButton:
An Image Button control is similar to a Button control, but it uses an image you supply in
place of the typical gray Windows-style button.
Property Description
Alternate Text Sets the text displayed when the mouse is paused
over the image
Example:
LinkButton:
A Link Button control renders a hyperlink on your page. From the point of view of
ASP.NET code Link Buttons can be treated in much the same way as buttons, hence the
name.
Example:
The Hyperlink control, which is similar to the Link Button control, creats a hyperlink on your page.
HyperLink Control:
Properties Description
Example:
RadioButton:
We can add individual radio buttons to the page one by one, using the RadioButton control. Radio
Buttons are grouped together using the GroupName property. Only one Radiobutton control from
each group can be selected at a time.
Example:
CheckBox:
we can use of CheckBox control to represent a choice that can be only a yes (checked) or no
(unchecked) value.
Example:
4. Explain about OLEDB connection class and page directive? (APR. 2016)
Constructors:
Constructors Description
DataSource Gets the server name or file name of the data source
Methods:
Methods Description
Example:
UNIT – V
2 MARKS
1. How an IP address is provided.(NOV.2014,APR.2014)
Addresses which are provided dynamically, are done so from a server on the network called a "DHCP"
(Dynamic Host Configuration Protocol) Server. The server is configured with a database that contains all of
the IP addresses available for use on the network
2. Give the expansion of SSL(APR.2013)
Secure Sockets Layer(SSL) is the standard security technology for establishing an encrypted link
between a web server and a browser.
This link ensures that all data passed between the web server and browsers remain private and integral.
SSL is an industry standard and is used by millions of websites in the protection of their online
transactions with their customers
3. Define Authentication(APR.2014,NOV.2013)
Authentication is the process of validating the identity of a user to allow or deny a request.
This involves accepting the credentials (eg.user name and password) from the users and validating it
against a designated authority.
4. What is the difference between node and host
Host:
For companies or individuals with a Web site, a host is a computer with a Web server that serves the
pages for one or more Web sites.
A host can also be the company that provides that service, which is known as hosting.
Node:
In a network, a node is a connection point, either a redistribution point or an end point for data
transmissions.
In general, a node has programmed or engineered capability to recognize and process or forward
transmissions to other nodes.
5. What is the purpose of routers
The main purpose of a router is to connect multiple networks and forward packets destined either for its own
networks or other networks.
A router is considered a layer-3 device because its primary forwarding decision is based on the information
in the layer-3 IP packet, specifically the destination IP address
6. Define protocol
A protocol defines rules and conventions for communication between network devices.
Protocols include mechanisms for devices to identify and make connections with each other, as well as
formatting rules that specify how data is packaged into messages sent and received
7. What is the role of server.(APR.2015)
A server role is a set of software programs that, when they are installed and properly configured, lets a
computer perform a specific function for multiple users or other computers within a network.
Generally, roles share the following characteristics. They describe the primary function, purpose, or use
of a computer.
8. Define MIME.(APR.2015)
MIME (Multi-Purpose Internet Mail Extensions) is an extension of the original Internet e-
mail protocol that lets people use the protocol to exchange different kinds of data files on the Internet: audio,
video, images, application programs, and other kinds
9. What are servlets.(APR.2015)
A servlet is simply a class which responds to a particular type of network request -
most commonly an HTTP request.
Basically servlets are usually used to implement web applications - but there are also
various frameworks which operate on top of servlets (e.g. Struts) to give a higher-
level abstraction than the "here's an HTTP request, write to this HTTP response" level
which servlets provide.
5 MARKS
1.What is meant by authentication? Explain.(APR.2014)
It is the process of ensuring the user’s identity and authenticity. ASP.NET allows four types of authentications:
Windows Authentication
Forms Authentication
Passport Authentication
Custom Authentication
1. WINDOWS AUTHENTICATION
If your application is targeted for use inside an organization, and users accessing the application have
existing user accounts within the local user database of the Web server or Active Directory, you should
authenticate users with Windows authentication.
2. FORMS AUTHENTICATION
By default, Form authentication is used. Form-based authentication presents the user with an
HTML-based Web page that prompts the user for credentials.
3. PASSPORT AUTHENTICATION
You can also authenticate users using a service from Microsoft called Passport. Passport is a
centralized directory of user information that Web sites can use, in exchange for a fee, to authenticate users.
Users can choose to allow the Web site access to personal information stored on Passport, such as the users'
addresses, ages, and interests.
4. CUSTOM AUTHENTICATION
When standard types of authentication do not meet your requirements, you need to modify an
authentication mechanism to create a custom solution. A user context has principal which represents the
identity and roles for that user. A user is authenticated by its identity and assigned roles to a user determine
about authorization or permission to access resources.
x = BCaps.Platform
This type of information is helpful because you may define more than one version of a Website. Each
version would be specialized so that it looked best for the specific browser that the visitor was using.
The BC.aspx ASP.NET page demonstrates the use of many of the properties of object. In code, the
values of the visitor’s browser are placed into a Label control .
Within the body of the page, the Label control is defined
<asp:Label
Id=”lblMessage1”
runat=”Server”
Font-Bold=”True”
/>
errorPage="/WebTest/ErrorPages/PageError.html"%>
The errorPage attribute maps to the Page.ErrorPage property, and hence may be set
programmatically. The value may optionally include query string parameters. If no parameters are added,
ASP.NET would automatically add one with the name aspxerrorpath. This parameter would hold the value
of the relative URL to this page, so that the error page would be able to determine which page caused the
error.
If a value is specified in this attribute (or property) and an unhandled exception occurs in the page,
the Pageclass would automatically perform a redirect to the specified page. If a value is not specified, the
exception is assumed to be unhandled, wrapped in a new HttpUnhandledException and then thrown,
propagating it to the next higher level.
Application Level:-
Use the customErrors section in web.config.
This section lets you specify the error page to which the user should be redirected to when an
unhandled exception propagates in the application level. This section specifies error pages for both
default errors as well as the HTTP status code errors.
<customErrors mode="On"
defaultRedirect="/WebTest/ErrorPages/AppError.html">
</customErrors>
The mode attribute specifies whether to show user-defined custom error pages or ASP.NET error
pages. Three values are supported for this attribute:
RemoteOnly - Custom error pages are shown for all remote users. ASP.NET error pages with rich error
information are displayed only for local users.
On - Custom error pages are always shown, unless one is not specified. When a custom error page is not
defined, an ASP.NET error page will be displayed which describes how to enable remote viewing of errors.
Off - Custom error pages are not shown. Instead, ASP.NET error pages will be displayed always, which will
have rich error information.
4. Write about IP address and authentication.(APR.2015)
(a). IP Address:-
An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer,
printer) participating in a computer network that uses the Internet Protocol for communication.
An IP address serves two principal functions: host or network interface identification and location
addressing.
Its role has been characterized as follows: "A name indicates what we seek. An address indicates where
it is. A route indicates how to get there.”
There are two versions of IP address, earlier Version of IP address is IPv4 contains IP address as 32 bit
number, and then because of growth of internet new version of IP is developed named IPv6 which takes
128 bit to store the IP Address.
(b). Authentication:-
It is the process of ensuring the user’s identity and authenticity. ASP.NET allows four types of
authentications:
Windows Authentication
Forms Authentication
Passport Authentication
Custom Authentication
1. WINDOWS AUTHENTICATION
If your application is targeted for use inside an organization, and users accessing the application have
existing user accounts within the local user database of the Web server or Active Directory, you should
authenticate users with Windows authentication.
2. FORMS AUTHENTICATION
By default, Form authentication is used. Form-based authentication presents the user with an
HTML-based Web page that prompts the user for credentials.
3. PASSPORT AUTHENTICATION
You can also authenticate users using a service from Microsoft called Passport. Passport is a
centralized directory of user information that Web sites can use, in exchange for a fee, to authenticate users.
Users can choose to allow the Web site access to personal information stored on Passport, such as the users'
addresses, ages, and interests.
4. CUSTOM AUTHENTICATION
When standard types of authentication do not meet your requirements, you need to modify an
authentication mechanism to create a custom solution. A user context has principal which represents the
identity and roles for that user. A user is authenticated by its identity and assigned roles to a user determine
about authorization or permission to access resources.
5. Describe about working with IIS
IIS Authentication:-
The Secure Socket Layer or SSL is the protocol used to ensure a secure connection. With SSL enabled,
the browser encrypts all data sent to the server and decrypts all data coming from the server. At the same time,
the server encrypts and decrypts all data to and from browser.
The URL for a secure connection starts with HTTPS instead of HTTP. A small lock is displayed by a
browser using a secure connection. When a browser makes an initial attempt to communicate with a server over
a secure connection using SSL, the server authenticates itself by sending its digital certificate.
To use the SSL, you need to buy a digital secure certificate from a trusted Certification Authority (CA)
and install it in the web server.
SSL is built into all major browsers and servers. To enable SSL, you need to install the digital
certificate. The strength of various digital certificates varies depending upon the length of the key generated
during encryption. More the length, more secure is the certificate, hence the connection.
Strength Description
40 bit Supported by most browsers but easy to break.
56 bit Stronger than 40-bit.
128 bit Extremely difficult to break but all the browsers do not
support it.
10. Where are cookies actually stored on the hard disk? Explain
A cookie is a piece of text that a web server can store on a user's hard disk. Cookies allow a Web site to
store information on a user's machine and later retrieve it. The pieces of information are stored as name-value
pairs.
For example, a Web site might generate a unique ID number for each visitor and store the ID number on
each user's machine using a cookie file.
If you use Microsoft's Internet Explorer to browse the Web, you can see all of the cookies that are stored
on your machine. The most common place for them to reside is in a directory called c:windowscookies. When I
look in that directory on my machine, I find 165 files. Each file is a text file that contains name-value pairs, and
there is one file for each Web site that has placed cookies on my machine.
You can see in the directory that each of these files is a simple, normal text file. You can see which Web
site placed the file on your machine by looking at the file name (the information is also stored inside the file).
You can open each file by clicking on it.
For example, I have visited goto.com, and the site has placed a cookie on my machine. The cookie file
for goto.com contains the following information:
UserID A9A3BECE0563982D www.goto.com/
Goto.com has stored on my machine a single name-value pair. The name of the pair is UserID, and the
value is A9A3BECE0563982D. The first time I visited goto.com, the site assigned me a unique ID value and
stored it on my machine.
(Note that there probably are several other values stored in the file after the three shown above. That is
housekeeping information for the browser.)
11. What is the difference between Logic controls and Form Authentication
Forms authentication can be easily implemented using login controls without writing any code.
Login control performs functions like prompting for user credentials, validating them and issuing
authentication just as the FormsAuthentication class.
However, all that’s needs to be done is to drag and drop the use control from the tool box to have these
checks performed implicitly.
The FormsAuthentication class is used in the background for the authentication ticket and ASP.NET
membership is used to validate the user credentials.
12. What is response object? How it is related to ASP's response object. (JULY 2012)
RESPONSE OBJECT:-
The Response object is used to send output to the client from the web server.
It is an instance of the System.Web.HttpResponse class.
In ASP.NET, the response object does not play any vital role in sending HTML text to the client,
because the server-side controls have nested, object oriented methods for rendering themselves.
Syntax:-
Response.collection|property|method
Collections:-
Collection Description
Cookies The Cookies collection sets the value of a cookie. If you attempt to set the value of a cookie that
does not exist, it is created. If it already exists, the new value you set overwrites the old value
already written to the client machine.
Properties:-
Property Description
Buffer The Buffer property determines whether to buffer page output or not. If set to True,
then output from the page is not sent to the client until the script on that page has been
processed, or until the Response object Flush or End methods are called.
CacheControl The CacheControl property determines whether proxy servers are able to cache the output
generated by ASP or not. If your page’s content is large and doesn’t change often, you
might want to allow proxy servers to cache the page. In this case set this property to
Public. Otherwise set it to Private.
Charset The Charset property appends the name of the character set to the Content-Type header in
the Response object.
ContentType The ContentType property specifies the HTTP content type for the response. If not
specified, the default is "text/html".
Expires The Expires property specifies the length of time (in minutes) that the client machine will
cache the current page. If the user returns to the page before it expires, the cached version
will be displayed.
ExpiresAbsolute The ExpiresAbsolute property specifies a date and time on which a page cached on a
browser will expire. If the user returns to the same page before that date and time, the user
will view the cached version of the page. If no time is specified, the page expires at
midnight on the date specified. If a date is not specified, the page expires at the given time
on the day that the script is run.
IsClientConnected The IsClientConnected property is a read-only property that indicates if the client has
disconnected from the web server since the last use of the Response object’s Write
method.
Pics The PICS (Platform for Internet Content Selection) property adds a value to the pics-label
field of the response header.
Status The Status property specifies the value of the status line that is returned to the client
machine from the web server.
Methods:-
Method Description
AddHeader The AddHeader method allows you to add your own HTTP header with a specified
value. If you add an HTTP header with the same name as a previously added header,
the second header will be sent in addition to the first; adding the second header does not
overwrite the value of the first header with the same name. Also, once the header has
been added to the HTTP response, it cannot be removed.
AppendToLog The AppendToLog method adds a string to the end of the Web server log entry for the
current page request. You can only add up to 80 characters at a time, but you can call
this method multiple times.
BinaryWrite The BinaryWrite method writes information directly to the output without any character
conversion.
Clear The Clear method erases any buffered HTML output. It does so without sending any of
the buffered response to the client. Calling Clear will cause an error if Buffer property
of the Response object is not set to True.
End The End method stops the processing of the script in the current page and sends the
already created content to the client. Any code present after the call to the End method
is not processed.
Flush The Flush method sends buffered output to the client immediately. Flush will cause a
run-time error if Buffer property of the Response object is not set to True.
10 MARKS
1. How security can be provided by SSL and client certificates? Explain.(APR.2014, JULY 2014)
SSL BASICS:-
Secure Sockets Layer(SSL) is the standard security technology for establishing an encrypted link
between a web server and a browser.
This link ensures that all data passed between the web server and browsers remain private and integral.
SSL is an industry standard and is used by millions of websites in the protection of their online
transactions with their customers
SSL Element:-
The main role of SSL is to provide security for Web traffic. Security includes confidentiality, message
integrity, and authentication.
SSL achieves these elements of security through the use of
Cryptography
Digital Signatures
Certificates
1. Cryptography:-
SSL protects confidential information through the use of cryptography. Sensitive data is encrypted
across public networks to achieve a level of confidentiality.
There are two types of data encryption:
Symmetric cyrptography
Asymmetric cryptography
(i)Symmetric Cryptography:-
Symmetric cryptography uses a single key for encryption and decryption.
Symmetric cryptography requires that both parties have the key.
Key distribution is the inherent weakness in symmetric cryptography
Minimal CPU cycles are required to verify keys
Symmetric ciphers are fortified by algorithmic strength and key lengths.
SSL symmetric key lengths range from 40 to 168 bits.
(ii)Asymmetric Cryptography:-
Asymmetric cryptography was designed in response to the limitations of symmetric
cryptography
Information encrypted with one key can be decrypted only with another key
Public key infrastructure (PKI) cryptography is up to 1000 times more than CPU intensive than
symmetric cryptography
The Rivest,Shamir,Adelman(RSA) algorithm uses modular arithmetic to enable the concept of
public and private keys
All SSL transactions begin with an asymmetric key exchange.
CLIENT CERTIFICATION:-
SSL uses digital certificates to authenticate servers. (SSL also includes an optional authentication for
clients). Certificates are digital documents that will attest to the binding of a public key to an individual or other
entity. They allow verification of the aim that a specific public key does, in fact, belong to the specified entity.
Certificates help prevent someone from impersonating the server with a false key. SSL uses X.509 certificates
to validate identities.
X.509 certificates contain information about the entity including public key and name. A certificate
authority then validates this certificate.
PAGE DIRECTIVES:-
The page directives set up the environment for the page to run. The @Page directive defines page-
specific attributes used by ASP.NET page parser and compiler. Page directives specify how the page should be
processed, and which assumptions need to be taken about the page. It allows importing namespaces, loading
assemblies, and registering new controls with custom tag names and namespace prefixes.
The Page directive defines the attributes specific to the page file for the page parser and the compiler.
The basic syntax of Page directive is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Trace="true" %>
Later in code, when you get to the point at which you need to connect to the database, you will
instantiate the object and supply the object with the connect string in that statement:
MyConnection = New
OleDbConnection(“PROVIDER=” _
& ”ProvidenName;” _
& ”DataSourceName;” _
A connect string & ”Other Parameter=” _ is made up of parameters
that are needed to connect to the database
successfully. Each of the & ”OtherParameterValue” _) parameters contains the
name of the parameter followed by its value
preceded by an equal sign. Each parameter in the connect string is separated by a semicolon.
Connect string vary depending on the type of the database you are connecting to, but, typically, they
contain the name of the provider, which is the library to use to connect to the database, and some path or name
for the database. Often you will find parameters such as user names and passwords that are associated with a
database in a connect string.
A connect string to an Access database frequently look like this:
MyConnection = New OleDbConnection(“PROVIDER=”
_
& “Microsoft.Jet.OLEDB.4.0;” _
& “c:\SomeFolder\DBName.mdb”)
The first parameter states the name of the provider to use to connect to the Access database
The second parameter specifies the full path to the database to open.
Once you have supplied a connect string, you connect to the database by calling the Open method:
MyConnection.Open()
When you have finished with a database connection, you disconnect from the database by calling the
Close method:
MyConnection.Close()
When using authentication with client certificates, each user needs to possess a key pair, consisting of a
public and a private key. The public key is contained in the X.509 client certificate and can be made public.
However, the user's private key needs to be kept safe.
The possibilities available for securing the private key depend on the Web browser that you use. (For
example, you may be able to protect it with a password or you may be able to use smart cards.) If the private
key is stored on the front-end client, your users should use screensavers protected with a password.
If users share Web browsers for clients, then note the following:
As long as the operating system separates and protects user data at the operating system level (for example,
Windows NT), then the private key stored on the Web front-end client is protected by the operating system.
Syntax:-
Request[.collection|property|method](variable)
Collections:-
Collection Description
ClientCertificate The ClientCertificate collection provides access to the
certification fields from a request issued by the web
browser. Commonly, it is used when the client is requesting
secure pages through SSL connection. Before using this
collection, you must configure your Web server to request
client certificates.
Cookies The Cookies collection allows you to retrieve the values of
the cookies sent in an HTTP request.
Form The Form collection allows you to retrieve the data input
into an HTML form posted to the HTTP request body by a
form using the POST method.
QueryString The QueryString collection allows you to retrieve the values
of the variables in the HTTP query string. For example, it
parses the values sent by a form using the GET Method. The
QueryString collection is less capable than the Form
collection, since there is a limit to the amount of data that
can be sent in the header of an HTTP request.
ServerVariables The ServerVariables collection contains the values of
predefined environment variables plus all of the HTTP
header values sent from the client browser to the web server.
Properties:-
Property Description
TotalBytes The TotalBytes property is a read-only
property that specifies the total number of
bytes sent by the client in the HTTP request
body. It is important when preparing to read
data from the request body using the
BinaryRead method of the Request object.
Methods:-
Method Description
BinaryRead The BinaryRead method retrieves the data sent to the
server from the client as part of a POST request and stores
it in a SafeArray. A SafeArray is a special variant array
that contains, in addition to its items, the number of
dimensions in the array and the upper bounds of the array.
RESPONSE OBJECT:-
The Response object is used to send output to the client from the web server.
It is an instance of the System.Web.HttpResponse class.
In ASP.NET, the response object does not play any vital role in sending HTML text to the client,
because the server-side controls have nested, object oriented methods for rendering themselves.
Syntax:-
Response.collection|property|method
Collections:-
Collection Description
Cookies The Cookies collection sets the value of a cookie. If you attempt to set the value of a cookie that
does not exist, it is created. If it already exists, the new value you set overwrites the old value
already written to the client machine.
Properties:-
Property Description
Buffer The Buffer property determines whether to buffer page output or not. If set to True,
then output from the page is not sent to the client until the script on that page has been
processed, or until the Response object Flush or End methods are called.
CacheControl The CacheControl property determines whether proxy servers are able to cache the output
generated by ASP or not. If your page’s content is large and doesn’t change often, you
might want to allow proxy servers to cache the page. In this case set this property to
Public. Otherwise set it to Private.
Charset The Charset property appends the name of the character set to the Content-Type header in
the Response object.
ContentType The ContentType property specifies the HTTP content type for the response. If not
specified, the default is "text/html".
Expires The Expires property specifies the length of time (in minutes) that the client machine will
cache the current page. If the user returns to the page before it expires, the cached version
will be displayed.
ExpiresAbsolute The ExpiresAbsolute property specifies a date and time on which a page cached on a
browser will expire. If the user returns to the same page before that date and time, the user
will view the cached version of the page. If no time is specified, the page expires at
midnight on the date specified. If a date is not specified, the page expires at the given time
on the day that the script is run.
IsClientConnected The IsClientConnected property is a read-only property that indicates if the client has
disconnected from the web server since the last use of the Response object’s Write
method.
Pics The PICS (Platform for Internet Content Selection) property adds a value to the pics-label
field of the response header.
Status The Status property specifies the value of the status line that is returned to the client
machine from the web server.
Methods:-
Method Description
AddHeader The AddHeader method allows you to add your own HTTP header with a specified
value. If you add an HTTP header with the same name as a previously added header,
the second header will be sent in addition to the first; adding the second header does not
overwrite the value of the first header with the same name. Also, once the header has
been added to the HTTP response, it cannot be removed.
AppendToLog The AppendToLog method adds a string to the end of the Web server log entry for the
current page request. You can only add up to 80 characters at a time, but you can call
this method multiple times.
BinaryWrite The BinaryWrite method writes information directly to the output without any character
conversion.
Clear The Clear method erases any buffered HTML output. It does so without sending any of
the buffered response to the client. Calling Clear will cause an error if Buffer property
of the Response object is not set to True.
End The End method stops the processing of the script in the current page and sends the
already created content to the client. Any code present after the call to the End method
is not processed.
Flush The Flush method sends buffered output to the client immediately. Flush will cause a
run-time error if Buffer property of the Response object is not set to True.
Syntax:-
Request.BinaryRead(count)
Examples
Parameter Description
Count Requires. Specifies how many bytes to read
from the client
The following example uses the BinaryRead method to place the content of a request into a safe array:
<%
dim a,b
a=Request.TotalBytes
b=Request.BinaryRead(a)
%>