Set-1 Final by Aparna (1

Web Technologies (April/May-2012, Set-1) JNTU-Anantapur
S.1
Set-1
Code No.: 9A05701/R09
III B.Tech. II Semester Regular Examinations
Solutions
April/May - 2012
WEB TECHNOLOGIES
( Common to Information Technology and Computer Science & Systems Engineering )
Time: 3 Hours
Max. Marks: 70
Answer any FIVE Questions
All Questions carry equal marks
---
1.
Explain the two uses of tables. Quote suitable HTML code examples in the discussions. (Unit-VI, Topic No. 6.1)
2.
Design an XML schema for hospital information management. Include every feature available into the schema.
(Unit-VIII, Topic No. 8.1)
3.
(a)
Discuss in detail data type of Java script. (Unit-III, Topic No. 3.1)
(b)
Write a script that prints a rectangle and oval using ‘*’ character. (Unit-III, Topic No. 3.1)
4.
Take the tick tock bean available in BDK, build an application which controls the color beam. Develop the necessary
code to exhibit the bound properties of JAVA beans with the above mentioned beans. (Unit-IV, Topic No. 4.6)
5.
(a)
How to set a cookie on user computer? Explain with an example. (Unit-V, Topic No. 5.1)
(b)
Explain briefly how to redirect the HTTP headers to different locations. (Unit-V, Topic No. 5.2)
(a)
How to perform a query in PHP? Explain with PHP code. (Unit-VII, Topic No. 7.1)
(b)
Briefly explain about the MVC architecture. (Unit-VII, Topic No. 7.5)
(a)
List and describe the different form elements associated with common form issues. (Unit-VI, Topic No. 6.1)
(b)
Differentiate GET and POST methods. (Unit-VI, Topic No. 6.2)
(a)
How to initialize the XML parser in PHP? Explain with an example. (Unit-VIII, Topic No. 8.1)
(b)
What is W3C DOM? Explain different parts and levels of W3C DOM. (Unit-VIII, Topic No. 8.1)
6.
7.
8.
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Spectrum ALL-IN-ONE Journal for Engineering Students, 2013
S.2
SOLUTIONS TO APRIL/MAY-2012, SET-1, QP
Q1. Explain the two uses of tables. Quote suitable HTML code examples in the discussions.
Answer :
April/May-12, Set-1, Q1
Uses of Tables
1.
Tables are useful in displaying the data in a two-dimensional tabular format. To display the data in the tabular form,
HTML provides a <table></table> tag which is the container of the whole table. The table is made up of number of
rows that are inturn made up of number of cells. A row within the table is specified by using the tag <tr><1tr>. The
cells within the rows are specified by using the tag <td><1td>. Tables can be rendered by with the name and the
column header which can be done by using the tags <caption> and <th>. This usage can be be shown with the help
of following HTML code table.html.
Table.html
<html>
<head></head>
<body>
<table border = “1” align = “center”>
<tr bgcolor = “pink”><th>Books</th><th>Authors</th></tr>
<tr><td>PHP5</td><td>Lee Babin</td></tr>
<tr><td>Web Technologies</td><td>Sebesta</td>></tr>
<tr><td>Java</td><td><Schidt</td></tr>
</table>
</body>
</html>
Output
2.
Table are useful in combining different alignment of the text within a single page. This can be done by using align
attribute. The values taken by this attribute are left, right and centre. This can be shown in the following HTM code
(aligh.html).
<html>
<head></head>
<body>
<table border = “0”>
<tr><th align = “left”>Apple</th><td align = “right”>The apple is the pomaceous fruit of the apple tree, species
Malus domestica in the rose family (Rosaceae). It is one of the most widely cultivated tree fruits, and the most widely
known of the many members of genus Malus that are used by humans. Apples grow on small, deciduous trees. The
tree originated in west.</td></tr>
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Web Technologies (April/May-2012, Set-1) JNTU-Anantapur
S.3
<tr><th align = “left”>Grapes</th><td align = “center” > The grapefruit (Citrus × paradisi) is a subtropical citrus tree
known for its bitter fruit, an 18th - century hybrid first bred in Barbados. [1] When found, it was named the “forbidden
fruit”; [2] and it has also been misidentified with the pomelo or shaddock (C. maxima), one of the parents of this
hybrid.</td></tr>
<tr><th align = “left”>Mango</th><td align = “right”>The mango is a fleshy stone fruit belonging to the genus
Mangifera, consisting of numerous tropical fruiting trees in the flowering plant family Anacardiaceae. The mango is
native to South Asia, from where it has been distributed worldwide to become one of the most cultivated fruits in the
tropics</td></tr>
</table>
<body>
</html>
Output
In the above output all the contents of the table headers are aligned at left whereas the content of the first and third
row’s table data are aligned at right and the content of the second row’s table data is aligned at center.
Q2. Design an XML schema for hospital information management. Include every feature available
into the schema.
Answer :
April/May-12, Set-1, Q2
Schema for Hospital Information
<?xml version = “1.0” encoding = “utf-8”?>
<xsd: schema xmlns : xsd = “http://www.w3.org/2001/xmlschema”>
<xsd: element name = “xyz hospital”>
<xsd: complex type>
<xsd: sequence>
<xsd: element name = “department”>
<xsd: complex type>
<xsd: sequence>
<xsd: element name = “doctor’s name” type = “xsd: string”/>
<xsd: element name = “patient’s name” type = “xsd: string”/>
<xsd: element name = “diagnosis” type = “xsd: string”/>
<xsd: element name = “date of visit”>
<xsd: complex type>
<xsd: attribute name = “month” type = xsd: integer/>
<xsd: attribute name = “day” type = xsd: integer/>
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
S.4
Spectrum ALL-IN-ONE Journal for Engineering Students, 2013
</xsd: complex type>
</xsd: element>
<xsd: element name = “time”>
<xsd: complex type>
<xsd: element name = “hour”>
<xsd: complex type>
<xsd: attribute name = “hr” type = “xsd: integer”/>
<xsd: attribute name = “min” type = “xsd:integer”/>
</xsd: complex type>
</xsd: element>
</xsd: sequence>
</xsd: complex type>
</xsd: element>
</xsd: sequence>
</xsd: complex type>
</xsd: schema>
Q3. (a) Discuss in detail data type of Java script.
Answer :
April/May-12, Set-1, Q3(a)
Data Types of JavaScript
JavaScript data types can be classified into mainly four types,
1.
Boolean data type
2.
String data type
3.
Null data type
4.
Number data type.
1.
Boolean Data Type
This data type consists of two logical values,
(a) True
(b) false
Example of few boolean data type,
(i) var snowing = false // Here var is a boolean data type where it displays the value false.
2.
String Data Type
In this data type of JavaScript, information is written in double quotes.
Example of few String Data Type,
(i) var name = “Amjad” :- Here var is a String data type which displays Amjad.
(ii) var greeting = “Hello” :- Var displays Hello.
3.
Null Data Type
The user can use this data type when he/she feels it does not want to initialize the value of a particular variable.
Example (i) var emp no = null;
(ii) var age = null;
4.
Number Data Type
This data type is just the opposite of String data type. The value is declared without double quotes.
Example of a number data type,
(i) var n1 = 30;
(ii) var rate = 800;
(iii) var amount = 9000;
(iv) var num = 50;
(v) var qty = 65.75;
(vi) var sal = 15000;
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Web Technologies (April/May-2012, Set-1) JNTU-Anantapur
(b) Write a script that prints a rectangle and oval using ‘*’ character.
Answer :
<html>
<head>
<title>Rectangle</title>
<body>
<center>
<script type = “text/javascript”>
document.writer(“<br>”);
document.write(“<br>”);
document.write(“<b>RECTANGLE</b>”+ “<br>”);
for(var i = 1; i<5; i ++)
{
for(var j = 1; j<15; j ++)
{
document.write(“*” + “ &nbsp”);
}
document.write(“<br>”);
}
document.write(“<br>”);
document.write(“<b>OVAL</b>” + “ <br>”);
for(var i = 1; i<9; i ++)
{
if((i ==1) | | (i ==8))
{
document.write(“&nbsp” + “&nbsp”);
for(var j = 1; j<9; j ++)
{
if((j ==1) | | (j ==2) | | (j==7) (j==8))
{
document.write(“&nbsp”);
continue;
}
else
{
document.write(“*”);
}
}
}
if((i==2) | | (i==7))
{
document.write(“&nbsp”);
for(var j = 1; j <9; j++)
B.Tech. III-Year II-Sem.
S.5
April/May-12, Set-1, Q3(b)
( JNTU-Anantapur )
Spectrum ALL-IN-ONE Journal for Engineering Students, 2013
S.6
{
if((j==1) | | (J==8))
{
document.write(“&nbsp”);
continue;
}
else
{
document.write(“*”);
}
}
}
if((i==3) | | (i==4) | | (i==5) | | (i==6))
{
document.write(“&nbsp”);
for(var j=1; j<9; j++)
{
document.write(“*”);
}
}
document.write(“<br>”);
}
</script>
</center>
</body>
</html>
Output
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Web Technologies (April/May-2012, Set-1) JNTU-Anantapur
S.7
Q4.
Take the tick tock bean available in BDK, build an application which controls the color beam.
Develop the necessary code to exhibit the bound properties of JAVA beans with the above mentioned beans.
Answer :
April/May-12, Set-1, Q4
Steps for Building an Application with TickTock Bean to Control the Colors Bean
Step 1
Start the Bean Development Kit (BDK)
Step 2
For answer refer Unit-IV, Q.No.8, Topic: Starting the Bean Development Kit (BDK).
Now, select the Colors Bean from the toolbar window by using a left mouse button. The cursor will be changed into
some shape. Next place the bean in the Beanbox window using the mouse cursor.
Step 3
Once the Colors Bean is instantiated, follow the same procedure for the TickTock Bean. As mentioned earlier, this
bean will be having an “interval” property. This property specifies how much time has passed among property
change events that were developed by TickTock Bean. The time is expressed in number of seconds. The default
value is 5. It should be changed to 1.
Step 4
Now, mapping should be done among the TickBean events and the Colors Bean methods. This further involves
three steps,
(i) In the first step, from the bean box window, select Edit option. Once you click this option, another option will
be displayed called Events. In the events, there will be a property change option, click on it. Once it is done,
small line will be formed from the button to the cursor.
(ii) Next, the mouse cursor should be moved in such a way that it is within the display area of the colors Bean. After
this, click the left button of the mouse. “An Event Target Dialog” dialog box will be seen.
(iii) The purpose of this dialog box is that it gives information regarding the invocation of a particular method for
the properly change event. After the invocation, an entry named “change” will be shown. Select it and click the
OK button.
Code to Exhibit the Bound Properties within TickTock Bean
import java.util.Date;
import java.lang;*;
import java.io.*;
import java.beans.*;
public class TickTockBean implements Runnable, Serializable
{
//instantiate property change support class
Private Property Change Support pct = new property change support transient thread runner = null;
Private int interval = 5;// interval variable of large int declared in private(The default value is 5);
Public TickTockBean( )
{
runner = new Thread(this); //Constructor
}
//Reset method
public void reset( )
{
if (runner! = null)
{
runner = new Thread(this);
runner.start( );
}
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Spectrum ALL-IN-ONE Journal for Engineering Students, 2013
S.8
}
public int getSeconds( )
{
return (int) ((new Date( )).getTime( )/1000);
}
public int getInterval( )
{
return interval; //method for obtaining the interval value
}
public int setInterval(int secs)
{
interval = secs; //for setting the interval value
if(runner! = null)
{
runner.interrupt( );
}
}
public void run( )
{
int oldseconds = getSeconds( );
for(; ;)
{
try
{
Thread.sleep(interval*1000);
}
catch(Interruptedexception(ie))
{
System.out.println(ie);
}
int newSeconds = getSeconds( );
pct.firePropertyChange(“Secs”, new Integer(old Second), new Integer(newSeconds));
oldSeconds = newSeconds;
}
}
//method for adding the listener
public void addPropertyChangeListener(PropertyChangeListener PW)
{
pcl.addPropertyChangeListener(pcl);
}
//method for removing listeners
public void removePropertyChangeListener(PropertyChangeListener pcl)
{
pct.removePropertyChangeListener(pcl);
}
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Web Technologies (April/May-2012, Set-1) JNTU-Anantapur
S.9
//seralization
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
{
ois.defaultReadObject ( );
reset( );
}
}
Q5. (a) How to set a cookie on user computer? Explain with an example.
Answer :
For answer refer Unit-V, Q1, Topics: Setting a Cookie, Example.
April/May-12, Set-1, Q5(a)
(b) Explain briefly how to redirect the HTTP headers to different locations.
Answer :
April/May-12, Set-1, Q5(b)
For answer refer Unit-V, Q3, Topic: Redirecting from a Script to a Different Location.
Q6. (a) How to perform a query in PHP? Explain with PHP code.
Answer :
For answer refer Unit-VII, Q2.
April/May-12, Set-1, Q6(a)
(b) Briefly explain about the MVC architecture.
Answer :
For answer refer Unit-VII, Q7.
April/May-12, Set-1, Q6(b)
Q7. (a) List and describe the different form elements associated with common form issues.
Answer :
April/May-12, Set-1, Q7(a)
For answer refer Unit-VI, Q1.
(b)
Differentiate GET and POST methods.
Answer :
For answer refer Unit-VI, Q2.
Q8.
(a)
April/May-12, Set-1, Q7(b)
How to initialize the XML parser in PHP? Explain with an example.
Answer :
April/May-12, Set-1, Q8(a)
Initializing the XML Parser in PHP
The following steps are involved in the initialization of a XML parser in PHP.
Use the xml_parser_create( ) function to initialize the XML parser.
Create the functions such that they can be used with different event handlers.
Use xml_set_element_handler( ) function to display the information about the functions that get executed
whenever the opening and closing tags are encountered by the parser.
Use xml_set_charecter_data_handler( ) function to display the information about the functions that get executed whenever the character data is encountered by the parser.
Use the xml_parse( ) function to parse the file “demo.xml”.
If the error encounters, use xml_error_string( ) function to convert a XML error into a textual error.
Use xml_parser_free( ) function to deallocate the memory occupied by the xml_parser_create( ) function.
Example
<?php
//iniliazes the XML parser
$p = xml_ parser_create ( );
function beginofelement ($p, $ele_nme, $ele_attributes)
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
S.10
Spectrum ALL-IN-ONE Journal for Engineering Students, 2013
{
switch($ele_nme)
{
case “NOTE”:
echo “_ _ Note _ _ <br>”;
break;
case “To”:
echo “To :”;
break;
case “FROM”:
echo “From:”;
break;
case “HEADING”:
echo “Heading :”;
break;
case “BODY” :
echo “Message: ”;
}
}
function endofelement($p, $ele_nme)
{
echo “<br>”;
}
function findchardata($p, $d)
{
echo $d;
}
xml_set_element_handler($p, “beginofelement”, “endofelement”);
xml_set_character_data_handler($p, “findchardata”);
$fp = fopen(“demo.xml”, “r”);
while($d = fread($fp, 4096))
{
xml_parse($p, $d, fee of ($fp)) or
die(sprintf(“Error in XML:%s at line %d”, xml_error_string(xml_get_error_code($p)),
xml_get_current_line_number($p)));
}
//deallocates the xml parser ‘p’
xml_parser_free($p);
?>
Output
_ _ Note _ _
To : Neeta
From : Reeta
Heading : Reminder
Message : Don’t forget my birthday !
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Web Technologies (April/May-2012, Set-1) JNTU-Anantapur
(b)
S.11
What is W3C DOM? Explain different parts and levels of W3C DOM.
April/May-12, Set-1, Q8(b)
Answer :
W3C DOM
The Document Object Model(DOM) is an Application Programming Interface (API) which is language neutral and
plat form independent. DOM accesses and manipulates the XML document. It is recommended by W3C hence it is referred
to as W3C DOM. DOM also provides standard set of interfaces to handle the structured information available in the form
of XML, HTML and other formats. Mainly it is an API which leads accesses, deletes and changes the elements of XML
document.
Parts and Levels of W3C DOM
The DOM has three different levels. That are,
(I)
DOM level 1
(II)
DOM level 2
(III) DOM level 3.
(I)
DOM Level 1
The DOM level 1 is divided into two parts,
1.
1.
Core and
2.
HTML.
Core
It includes set of fundamental interfaces at the low level that are used for representing the structured document.
These interfaces also define extended interfaces to represent an XML document.
2.
HTML
This part of level 1 includes extra higher-level interfaces combined with the fundamental interfaces to conveniently
view any HTML document.
The different interfaces available in this level are Document, Node, Attr, Element and Text that include attributes and
methods that help in interacting conveniently with HTML and XML documents.
(II)
DOM Level 2
The DOM level 2 is divided into six different parts. They are,
1.
1.
DOM2 Core
2.
DOM2 Views
3.
DOM2 Events
4.
DOM2 Css
5.
DOM2 Travel and Range
6.
DOM2 HTML.
DOM2 Core
It is an extension of DOM1 core. It includes the special method getElementById along with other namespace specific
methods. It also includes the interfaces to represent the XML document.
2.
DOM2 Views
It includes two interfaces, Abstract view and Document view. With the help of it the content of a representation of
a document can be dynamically accessed and updated by the programs and scripts
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )
Spectrum ALL-IN-ONE Journal for Engineering Students, 2013
S.12
3
DOM2 Events
It provides the event system for the programs and scripts. It includes the methods such as bubbling, cancellation,
event flow and capture along with the special methods addeventListener and handleEvent. The different interfaces
provided by DOM2 Events are, Event target, Eventlistener, Event, documentEvent, MouseEvent etc.
4.
DOM2 Css
It is also known as DOM2 style with which the content of the style sheets can be dynamically updated and accessed
by programs and scripts. It also include the interfaces for (Cssrule, Cascading style sheets, CssStyledeclaration,
style sheets and getComputed style.
5.
DOM2 Travel and Range
It includes the interfaces such as NodeIterator and TreeWalker to find out a range of content available in a document
by traversing dynamically.
The content range in a document, DocumentFragment or Attr can also be created, inserted, modified and deleted.
6.
DOM2 HTML
In this, the content and structure of HTML documents can be dynamically accessed and updated by the programs
and scripts. To access the document within a frame, it provides a property called contentDocument.
(III)
DOM Level 3
The DOM level 3 is divided into five different parts. They are,
1.
1.
DOM3 Core
2.
DOM3 Load and Save
3.
DOM3 Validation
4.
DOM3 Events
5.
DOM3 XPath.
DOM3 Core
It is an extension of DOM1 core and DOM2 core adopt Node( ) and text content are the new method and property
introduced in it.
2.
DOM3 Load and Save
In this, the content of a XML document can be loaded dynamically into a DOM document by the programs and
scripts.
3.
DOM3 Validation
In this, the content and structure of the documents can be dynamically updated by the programs and scripts to
indicate either the document is validated or is still need to be validated.
4.
DOM 3 Events
It is an enhancement of DOM2 Events. DOM2 Events do not include the keyboard events. The DOM3 Events
include the keyboard events and the way of handling them that are not specified by the DOM2 Events.
5.
DOM3 XPath
It includes simple functionalities that can be used to access a DOM tree with the help of X Path 1.0.
B.Tech. III-Year II-Sem.
( JNTU-Anantapur )