Web Technologies

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Name: SAMYA PAL

Roll No: 2114504018


Program: MCA
Semester: Sem2
Course Name: Web Technologies
Code: DCA6203
SET I

1)
a) What is an IP address? What are its types? Explain.
Ans:

An IP address is a numerical label assigned to the devices connected to a


computer network that uses the IP for communication. IP address act as an
identifier for a specific machine on a particular network. It also helps us to
develop a virtual connection between a destination and a source. The IP address
stands for Internet Protocol address is also called IP number or internet address.
It helps us to specify the technical format of the addressing and packets

There are mainly four types of IP addresses:


 Public,
 Private,
 Static
 Dynamic.

Among them, public and private addresses are based on their location of the
network private, which should be used inside a network while the public IP is
used outside of a network.

Public IP Addresses
A public IP address is an address where one primary address is associated with
our whole network. In this type of IP address, each of the connected devices has
the same IP address. This type of public IP address is provided to our router by
our ISP.

Private IP Addresses
A private IP address is a unique IP number assigned to every device that connects
to our home internet network, which includes devices like computers, tablets,
smartphones, which is used in our household.

It also likely includes all types of Bluetooth devices we use, like printers or
printers, smart devices like TV, etc. With a rising industry of internet of things
(IoT) products, the number of private IP addresses we are likely to have in our
own home is growing.
Dynamic IP address:
Dynamic IP addresses always keep changing. It is temporary and are allocated to
a device every time it connects to the web. Dynamic IPs can trace their origin to
a collection of IP addresses that are shared across many computers.

Dynamic IP addresses are another important type of internet protocol addresses.


It is active for a specific amount of time; after that, it will expire.

Static IP Addresses
A static IP address is an IP address that cannot be changed. In contrast, a dynamic
IP address will be assigned by a Dynamic Host Configuration Protocol (DHCP)
server, which is subject to change. Static IP address never changes, but it can be
altered as part of routine network administration.

Static IP addresses are consistent, which is assigned once, that stays the same
over the years. This type of IP also helps us procure a lot of information about a
device.

b) What is <img> tag? Why is it used? How can you insert an image
with rounded corners?
Ans:
HTML <img> tag is used to add image inside webpage/website. Nowadays
website does not directly add images to a web page, as the images are linked to
web pages by using the <img> tag which holds space for the image.

Syntax
<img src="" alt="" width="" height="">

The CSS property border-radius adds rounded corners on images. We can round
all of the image's corners or just select corners, vary the radius on different corners
or display an image in the shape of an oval or a circle.
2)
a) What is cascading style sheet (CSS)? How can you insert CSS in
HTML Page?
Ans:
Cascading Style Sheets, fondly referred to as CSS, is a simple design language
intended to simplify the process of making web pages presentable.
CSS handles the look and feel part of a web page. Using CSS, we can control the
color of the text, the style of fonts, the spacing between paragraphs, how columns
are sized and laid out, what background images or colors are used, layout
designs,variations in display for different devices and screen sizes as well as a
variety of other effects.
CSS is easy to learn and understand but it provides powerful control over the
presentation of an HTML document. Most commonly, CSS is combined with the
markup languages HTML or XHTML

CSS can either be attached as a separate document or embedded in the HTML


document itself. There are three methods of including CSS in an HTML
document:
 Inline styles — Using the style attribute in the HTML start tag.
 Embedded styles — Using the <style> element in the head section of a
document.
 External style sheets — Using the <link> element, pointing to an external
CSS file.

b) Explain Location object in JavaScript.


Ans:
JavaScript Location is a built-in Interface (object type) which represents the
location (URL) of the object to which it is attached. Both the Window object and
the Document object have this property. The window objects location property
gives us access to the browser window's location whereas the document location
property gives us the location object for a particular document.
It is used to fetch information of the current URL. The Location object allows us
to navigate to another webpage as well.
Suppose we want to get the current website's hostname then we can use
the hostname property of the location object.
JavaScript Location Object Properties

JavaScript Location Object has many properties using which we can access the
various components of a webpage's URL and even change it.

Example:

Property Description
href Represents a string specifying the entire URL, for instance
http://www.javascriptstudytonight.com:80/order.cgi?batch=1#intro
protocol Represents a String at the begining of a URL to the first
colon(:),which specifies the Method of access to the URL , for
instance http: or https:
host Represents a String consisting of hostname and port Strings,for
instance:- www.javascriptstudytonight.com:80

JavaScript Location Object Methods

Location Object methods refers to the functions created inside the location
interface which can be used to perform various operations on the URL like
reload it, change it, etc.

Example:

Method Description
assign() Loads a new Document in the
Browser
reload() Reloads the current document that is
contained in location.href property.
replace() Replaces the current document with
the specified new one. In addition,
you cannot navigate back to the
previous document using the
Browser's back button.
3)
a) Explain characteristics of JavaScript.
Ans:
1. JavaScript Lives in a Web Page
2. JavaScript is not server side language. It is client side language because it
is interpreted and run on the browser.
3. It is weakly typed because it does not need to specify datatypes to declare
variable (int, float, double etc) like c/c++.
4. It is not programming language. It Interpreted language because browsers
are interpret it.
5. JavaScript is case sensitive.
6. Semicolon(;) is optional
7. String can be enclosed by using single quote (‘) or double quote(“”)
8. // is used to specify single line comment and /* ... */ is used to specify
multiline comment.

b) What is event handling? How can you add an onclick event in HTML
page?
Ans:
Change in the state of an object is known as event i.e. event describes the
change in state of source. Events are generated as result of user interaction
with the graphical user interface components. For example, Clicking on a
button, moving the mouse, entering a character through keyboard, selecting
an item from list, scrolling the page are the activities that causes an event to
happen.
HTML <Button onClick=" ">

The Html <button onclick=" "> is an event attribute, which executes a script
when the button is clicked. This attribute is supported by all browsers. It is
also used to call a function when the button is clicked.

Syntax
<button onclick=" single value script">
SET II
4)
a) What is XMLHttpRequest object? Explain with an example.
Ans:
XMLHttpRequest (XHR) objects are used to interact with servers. We can
retrieve data from a URL without having to do a full page refresh. This enables
a Web page to update just part of a page without disrupting what the user is
doing. XMLHttpRequest is used heavily in AJAX programming. Despite its
name, XMLHttpRequest can be used to retrieve any type of data, not just
XML
XMLHttpRequest Example

When we type a character in the input field below, an XMLHttpRequest is


sent to the server, and some name suggestions are returned (from the server):

Start typing a name in the input field below:

Name: Suggestions:

Sending an XMLHttpRequest
Example
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
document.getElementById("demo").innerHTML =
xhttp.responseText;
}
};
xhttp.open("GET", "filename", true);
xhttp.send();
b) What are PHP variables? How you declare them? What are the
naming conventions for PHP variables?
Ans:
Variables in a program are used to store some values or data that can be used
later in a program. The variables are also like containers that store character
values, numeric values, memory addresses, and strings. PHP has its own way
of declaring and storing variables. There are a few rules, that need to be
followed and facts that need to be kept in mind while dealing with variables
in PHP.
In PHP variable we be declared as: $var_name = value;
Example:
<?php //
Declaring variables
$txt = "Hello World!";
$number = 10;
// Displaying variables value
echo $txt; // Output: Hello World!
echo $number; // Output: 10
?>

Naming Conventions for PHP Variables


These are the following rules for naming a PHP variable:
 All variables in PHP start with a $ sign, followed by the name of the
variable.
 A variable name must start with a letter or the underscore character _.
 A variable name cannot start with a number.
 A variable name in PHP can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _).
 A variable name cannot contain spaces.
5)
a) How can you load XML Data into an HTML Page? Explain with
example.
Ans:
Way to use XML data is to populate an HTML table with it
1. Start with an initial HTML document that has the following in the body
of the page:
<table id="MainTable">
<tbody id="BodyRows"></tbody>
</table>

2. The XML document that we'll load into this HTML has the following
structure. Note that the nodes for Employees 3 through 6 are collapsed
in the following image.
3. After the page loads, use JavaScript to run a function
called buildTable(), which in turn will run a function to populate the
table rows.
window.addEventListener("load", function() {
getRows();
});

4. Write the getRows() function to retreive the XML data using AJAX. If
the request succeeds, run a function called showResult().
function getRows() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("get", "Employees", true);
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
showResult(this);
}
};
xmlhttp.send(null);
}
5. Write showResult(), which will take the AJAX response as a parameter
function showResult(xmlhttp) {

}
6. Inside the showResult() function, extract the XML document from the
response object parameter
function showResult(xmlhttp) {
var xmlDoc = xmlhttp.responseXML.documentElement;
}

7. Write a new function called removeWhiteSpace(), which will remove


all non-visible characters from the XML and make it easier for us to
parse.
function removeWhitespace(xml) {
var loopIndex;
for (loopIndex = 0; loopIndex < xml.childNodes.length;
loopIndex++)
{
var currentNode = xml.childNodes[loopIndex];
if (currentNode.nodeType == 1)
{
removeWhitespace(currentNode);
}
if (!(/\S/.test(currentNode.nodeValue)) &&
(currentNode.nodeType == 3))
{
xml.removeChild(xml.childNodes[loopIndex--]);
}
}
}

8. Call removeWhiteSpace(), passing in the XML document.


function showResult(xmlhttp) {
var xmlDoc = xmlhttp.responseXML.documentElement;
removeWhitespace(xmlDoc);
}

9. Select the data in the XML document using getElementsByTagName.


function showResult(xmlhttp) {
var xmlDoc = xmlhttp.responseXML.documentElement;
removeWhitespace(xmlDoc);
var rowData = xmlDoc.getElementsByTagName("Employees");
}
10. Call a new function named addTableRowsFromXmlDoc(), which will
accept the XML data and the element where results should be output as
parameters.
function showResult(xmlhttp) {
var xmlDoc = xmlhttp.responseXML.documentElement;
removeWhitespace(xmlDoc);
var outputResult = document.getElementById("BodyRows");
var rowData = xmlDoc.getElementsByTagName(rowElement);
addTableRowsFromXmlDoc(rowData,outputResult);
}

11. Write the addTableRowsFromXmlDoc() function as follows


function addTableRowsFromXmlDoc(xmlNodes,tableNode) {
var theTable = tableNode.parentNode;
var newRow, newCell, i;
console.log ("Number of nodes: " + xmlNodes.length);
for (i=0; i<xmlNodes.length; i++) {
newRow = tableNode.insertRow(i);
newRow.className = (i%2) ? "OddRow" : "EvenRow";
for (j=0; j<xmlNodes[i].childNodes.length; j++) {
newCell = newRow.insertCell(newRow.cells.length);
if (xmlNodes[i].childNodes[j].firstChild) {
newCell.innerHTML =
xmlNodes[i].childNodes[j].firstChild.nodeValue;
} else {
newCell.innerHTML = "-";
}
console.log("cell: " + newCell);
}
}
theTable.appendChild(tableNode);
}

12. Run the script by opening it in a web browser. We can test it locally,
without a server, by creating a file named Employees.xml and changing
the URL in the XMLHttpRequest open() method to Employees.xml.
our finished HTML page and script should look like this:
b) What is a recordset object? Explain with example.
Ans:
A Recordset object represents the records in a base table or the records that
result from running a query. We use Recordset objects to manipulate data in
a database at the record level. When we use DAO objects, you manipulate data
almost entirely using Recordset objects. All Recordset objects are
constructed using records (rows) and fields (columns). There are five types
of Recordset objects:

 Table-type Recordset— representation in code of a base table that you


can use to add, change, or delete records from a single database table
(Microsoft Access workspaces only).
 Dynaset-type Recordset— the result of a query that can have updatable
records. A dynaset-type Recordset object is a dynamic set of records
that you can use to add, change, or delete records from an underlying
database table or tables. A dynaset-type Recordset object can contain
fields from one or more tables in a database. This type corresponds to
an ODBC keyset cursor.
 Snapshot-type Recordset— a static copy of a set of records that you can
use to find data or generate reports. A snapshot-type Recordset object
can contain fields from one or more tables in a database but can't be
updated. This type corresponds to an ODBC static cursor.
 Forward-only-type Recordset— identical to a snapshot except that no
cursor is provided. You can only scroll forward through records. This
improves performance in situations where you only need to make a
single pass through a result set. This type corresponds to an ODBC
forward-only cursor.
 Dynamic-type Recordset— a query result set from one or more base
tables in which you can add, change, or delete records from a row-
returning query. Further, records other users add, delete, or edit in the
base tables also appear in your Recordset. This type corresponds to an
ODBC dynamic cursor (ODBCDirect workspaces only).
Example: This example demonstrates Recordset objects and
the Recordsets collection by opening four different types of Recordsets,
enumerating the Recordsets collection of the current Database, and enumerating
the Properties collection of each Recordset.
Sub RecordsetX()
Dim dbsNorthwind As Database
Dim rstTable As Recordset
Dim rstDynaset As Recordset
Dim rstSnapshot As Recordset
Dim rstForwardOnly As Recordset
Dim rstLoop As Recordset
Dim prpLoop As Property

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

With dbsNorthwind

' Open one of each type of Recordset object.


Set rstTable = .OpenRecordset("Categories", _
dbOpenTable)
Set rstDynaset = .OpenRecordset("Employees", _
dbOpenDynaset)
Set rstSnapshot = .OpenRecordset("Shippers", _
dbOpenSnapshot)
Set rstForwardOnly = .OpenRecordset _
("Employees", dbOpenForwardOnly)

Debug.Print "Recordsets in Recordsets " & _


"collection of dbsNorthwind"

' Enumerate Recordsets collection.


For Each rstLoop In .Recordsets

With rstLoop
Debug.Print " " & .Name

' Enumerate Properties collection of each


' Recordset object. Trap for any
' properties whose values are invalid in
' this context.
For Each prpLoop In .Properties
On Error Resume Next
If prpLoop <> "" Then Debug.Print _
" " & prpLoop.Name & _
" = " & prpLoop
On Error GoTo 0
Next prpLoop

End With

Next rstLoop

rstTable.Close
rstDynaset.Close
rstSnapshot.Close
rstForwardOnly.Close

.Close
End With

End Sub
6)
a) Explain comparison operators used in PHP.
Ans:
The Word Comparison in Comparison Operators in PHP itself says that the
operators are generally used for comparing any two values/variable values
(variable values can be a string or a number or any other to compare). Equal,
Identical, Not Equal, Not identical, Greater than, Less than, Greater than or
equal to, Less than or equal to are some of the comparison operator names to
compare any two types of similar type of values based on our requirement.
Operator Name Example Result
== Equal $x == $y TRUE if $x is exactly equal to
$y
=== Identical $x === $y TRUE if $x is exactly equal to
$y, and they are of the same
type.
!= Not equal $x != $y TRUE if $x is exactly not
equal to $y.
<> Not equal $x <> $y TRUE if $x is exactly not
equal to $y.
!== Not identical $x !== $y TRUE if $x is not equal to $y,
or they are not of the same
type.
< Less than $x < $y TRUE if $x (left-hand
argument) is strictly less than
$y (right-hand argument).
> Greater than $x > $y TRUE if $x (left hand
argument) is strictly greater
than $y (right hand argument).
<= Less than or $x <= $y TRUE if $x (left hand
equal to argument) is less than or
equal to $y (right hand
argument).
>= Greater than or $x >= $y TRUE if $x is greater than or
equal to equal to $y.

b) Write a program in ASP to calculate factorial of a given number


using while loop?
Ans:
<html>
<body>
<title>Factorial Program in Classic ASP</title>
<!-- form post method -->
<form action="" method="post">
<label>Enter a Number to calculate Factorial</label> <input type="text"
name="number" size="2" />
<input type="submit" value="Find" name="submit" />
</form>
</body>
</html>

<%
'check for form submission and then allow
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
fact = 1
'get the value from input text box 'number'
number = Request.form("number")
Response.Write("Factorial of "+number+"<br><br>")

i=1
Do until i = number
'formula to calculate factorial is to
'multiply the iterator i value with fact value.
fact = fact * i

'print fact to show the factorial pyramid


'or put this line out of this 'for loop' to show only the total value
Response.Write(fact)
Response.Write("<br>")
i=i+1
Loop
end if

You might also like