Module 4,5 and 6 Imp Ques

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

Internet Programming

Question Bank

Unit 4: Rich Internet Application (RIA)


1. State characteristics of Rich Internet Application (RIA) [02]
Ans:
1. Offline use - When connectivity is unavailable, it might still be possible to use
an RIA. An RIA platform let the user work with the application without
connecting to the Internet and synchronizing it automatically when the user goes
live.
2. Consistency of look and feel - With RIA tools, the user interface and experience
with different browsers, devices and operating systems can be more carefully
controlled and made consistent
3. Partial-page updating - RIAs incorporate additional technologies, such as real-
time streaming, high-performance client-side virtual machines, and local caching
mechanisms that reduce latency (wait times) and increase responsiveness.
4. Rapid Development - An RIA Framework should facilitate rapid development
of a rich user experience through its easy-to-use interfaces in ways that help
developers.

2. Explain the working of AJAX [05]


Ans:
1. Ajax communicates with the server by using XMLHttpRequest Object.
2. Users send request from User Interface and JavaScript call goes to the
XMLHttpRequest Object after that XMLHttp request is sent to the
XMLHttpRequest Object.
3. At that time server interacts with the database using php, servelet, ASP.net etc.
4. The data is retrieved then the server sends data in the form of XML or Jason
data to the XMLHttpRequest Callback function.
5. Then HTML and CSS displayed the Data on the browser.
In Ajax model, there is an Ajax engine involved in between the user and the server,
which eliminates the to and fro from the user to the server and back. This Ajax engine
is written in JavaScript and is in a hidden frame. It handles the user front by
communicating to the user as well as handles the server front by itself. This way, the
end user barely faces a waiting period.

3. How is AJAX architecture different from the traditional Web application model
Ans:
Conventional model AJAX model

The browser sends an HTTP request to the The browser creates a JavaScript call, which
server. then creates a new XMLHttpRequest object.
The new XMLHttpRequest object transfers
The web server receives and processes the
data between the browser and the web server
request.
in an XML format.
The XMLHttpRequest object sends a request
The web server sends the requested data to for the updated page data to the web server.
the browser. Subsequently, the latter processes the request
and sends it back to the browser.
The browser receives the data from the server The browser uses JavaScript to process the
and reloads it as an HTML page. response and displays the updated content

Users must wait until it finishes loading.


Therefore, the conventional model increases The updated content directly on the HTML
the load on the server and is more time- page without reloading.
consuming.

4. How to create XMLHttpRequest object in AJAX. [02]


Ans: XMLHTTPRequest object is an API which is used for fetching data from the
server.
Syntax for creating an XMLHttpRequest object:
xhttp = new XMLHttpRequest();
Microsoft Internet Explorer 6 or earlier version, are unable to deal with
XMLHttpRequest object. Thus, use following
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
5. Explain AJAX methods provided by jQuery with example [02]
Ans: jQuery load() Method
1. The jQuery load() method is a simple, but powerful AJAX method.
2. The load() method loads data from a server and puts the returned data into the
selected element.
3. Syntax: $(selector).load(URL,data,callback);
The required URL parameter specifies the URL you wish to load.
The optional data parameter specifies a set of query string key/value pairs to
send along with the request.
The optional callback parameter is the name of a function to be executed after
the load() method is completed.
4. Example: $("#div1").load("demo_test.txt");

6. State the various ways of receiving response from server using AJAX. Support your
answer with an example [05]
Ans: Various ways of receiving response from a server, is by using responseText or
responseXML property of the XMLHttpRequest object.
a) The responseText Property: If the response from the server is not XML,
use the responseText property. The responseText property returns the
response as a string, and you can use it accordingly
b) The responseXML Property: If the response from the server is XML, and
you want to parse it as an XML object, use the responseXML property.
Example:
<!DOCTYPE html>
<html> <body>
<div id="demo">
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
<script>
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
xhttp.open("GET", "Hello.txt");
xhttp.send();
}
</script> </body> </html>

7. How jQuery uses GET and POST methos to request data from server [05]
Ans:
jQuery $.get() Method: The $.get() method requests data from the server with an
HTTP GET request.
Syntax: $.get(URL,callback);
The required URL parameter specifies the URL you wish to request.
The optional callback parameter is the name of a function to be executed if the
request succeeds.
The following example uses the $.get() method to retrieve data from a file on
the server:

jQuery $.post() Method: The $.post() method requests data from the server using an
HTTP POST request.
Syntax: $.post(URL,data,callback);
The required URL parameter specifies the URL you wish to request.
The optional data parameter specifies some data to send along with the request.
The optional callback parameter is the name of a function to be executed if the
request succeeds.
The following example uses the $.post() method to send some data along with
the request:
$("button").click(function(){
$.post("demo_post.asp",
{
name: "Ankita",
city: "Kandivali"
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Unit 5: Web Extensions: PHP and XML
1. Distinguish between echo and print statement in PHP [02]
Ans:
echo statement print statement

It is used to display the output. print is also a statement, used as an


alternative to echo at many times to
display the output.
It can be used with or without parentheses. print can be used with or without
parentheses.
echo does not return any value. print always returns an integer value,
which is 1.
We can pass multiple strings separated by Using print, we cannot pass multiple
comma (,) in echo. arguments.
e.g e.g
<?php <?php
$fname = "Ankita"; $fname = "Ankita";
$lname = "Karis"; $lname = "Karis";
echo "My name is: ".$fname,$lname; print "My name is: ".$fname,$lname;
?> ?>
The above statement will give successful It will generate a syntax error because of
output multiple arguments in a print statement.
echo is faster than print statement. print is slower than echo statement.

2. State and explain various types of arrays in PHP [05]


Ans: There are 3 types of array in PHP.
1. Indexed Array: PHP index is represented by number which starts from 0.
We can store number, string and object in the PHP array. All PHP array
elements are assigned to an index number by default.
Example:
<?php
$season=array("summer","winter","spring","autumn");
echo "Season are: $season[0], $season[1], $season[2] and $season[3]";
?>

2. Associative Array: Associative arrays are arrays that use named keys that
you assign to them.
Example:
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
} ?>
3. Multidimensional Array: A multidimensional array is an array containing
one or more arrays. PHP supports multidimensional arrays that are two,
three, four, five, or more levels deep.
<?php
$emp = array
(
array(1,"sonu",400000),
array(2,"john",500000),
array(3,"rahul",300000)
);
for ($row = 0; $row < 3; $row++) {
for ($col = 0; $col < 3; $col++) {
echo $emp[$row][$col]." ";
}
echo "<br/>";
} ?>

3. Write a PHP program to reverse a number [02]


<html> <body>
<form action="reversenum.php" method="get">
Name: <input type="number" name="n1"> <br><br>
<input type="submit" value="Submit">
</form>
</body> </html>
reversenum.php
<?php
$num = $_GET['n1'];
$rev=0;
$n=$num;
while($num!=0)
{
$rem=$num%10;
$rev=($rev*10)+$rem;
$num=(int)($num/10);
}
echo "<b>Reverse of</b>".$n."<b> = </b>".$rev;
?>

4. Create an HTML form that accepts Emp_Id, First_Name, Last_Name and Gender from
user. Write a PHP code to store this information into Employee table using MySQL
database [05]

connect.php

<?php
session_start();
$dbHost='localhost';
$dbName='Employee';
$dbUsername='root';
$dbPassword='';
$dbc=mysqli_connect($dbHost,$dbUsername,$dbPassword,$dbName);
if(!$dbc){
die('Could not Connect My Sql:' .mysql_error());
}
// else{
// echo "Connected";
// }
?>
Data.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Details</title>
</head>
<body>
<form action="insert.php" method="post">
Employee Id : <input type="text" name="eid">
<br><br>
First Name : <input type="text" name="fname">
<br><br>
Last Name : <input type="text" name="lname">
<br><br>
Gender : <input type="text" name="gender">
<input type="submit" value="Submit" name="save">
</form>
</body>
</html>

insert.php

<?php

include"connect.php";
if(isset($_POST['save']))
{
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$emp_id = $_POST['eid'];
$Gender = $_POST['gender'];
$sql = "INSERT INTO Emp_Details
(Emp_Id,First_Name,Last_Name,Gender)
VALUES ('$emp_id','$first_name','$last_name','$Gender')";
if (mysqli_query($dbc,$sql)) {
echo "New record created successfully !";
} else {
echo "Error: " . $sql . " " . mysqli_error($dbc);
}
mysqli_close($dbc);
}
?>
5. Display the following information using XML and XSLT [05]

<?xml version="1.0" encoding="UTF-8"?>


<?xml-stylesheet type="text/xsl" href="QBank.xsl"?>

<store>
<book id ="5350192956">
<bookname>XSLT Programmer's Reference</bookname>
<authorname>Michael Kay</authorname>
<publisher>Wrox</publisher>
<price>$40</price>
<edition>4th</edition>
</book>
<book id ="3741122298">
<bookname>Head First Java</bookname>
<authorname>Kathy Sierra</authorname>
<publisher>O'reilly</publisher>
<price>$19</price>
<edition>1st</edition>
</book>
<book id ="9987436700">
<bookname>SQL The Complete Reference</bookname>
<authorname>James R. Groff</authorname>
<publisher>McGraw-Hill</publisher>
<price>$45</price>
<edition>3rd</edition>
</book>
</store>

QBank.xsl

<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result
prefixes="xs" version="2.0">
<xsl:template match = "/store">
<html> <body>
<h2>Books:-</h2>
<table border = "1">
<tr bgcolor = "#dbe2f0">
<th>Book ID</th>
<th>Book Name</th>
<th>Author Name</th>
<th>Publisher</th>
<th>Price</th>
<th>Edition</th>
</tr>
<xsl:for-each select="book">
<tr bgcolor = "#aee7f0">
<td><xsl:value-of select = "@id"/></td>
<td><xsl:value-of select = "bookname"/></td>
<td><xsl:value-of select = "authorname"/></td>
<td><xsl:value-of select = "publisher"/></td>
<td><xsl:value-of select = "price"/></td>
<td><xsl:value-of select = "edition"/></td>
</tr>
</xsl:for-each>
</table>
</body> </html> </xsl:template> </xsl:stylesheet>
6. State the syntax of “foreach loop” in PHP with example [02]
Ans: The foreach loop is used to traverse the array elements. It works only on array and
object. It will issue an error if you try to use it with the variables of different datatype.
The foreach loop works on elements basis rather than index. It provides the easiest way
to iterate the elements of an array. In foreach loop, we don't need to increment the value.

Synatx:
foreach ($array as $value) {
//code to be executed
}
Example:
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>

Unit 6: ReactJS
1. State features of ReactJS [02]
2. Create a simple application using ReactJS [02

You might also like