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

Register No.

SNS COLLEGE OF ENGINEERING


Kurumbapalayam (Po), Coimbatore – 641 107
AN AUTONOMOUS INSTITUTION
Accredited by NBA – AICTE and Accredited by NAAC – UGC with ‘A’ Grade
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai

INTERNAL ASSESSMENT EXAMINATION - III


COURSE: B.Tech. –IT
IT8501 – Web Technology
Sem & Class: V Sem/III-IT Date: 15.10.2019
Duration: 1 Hour 30 Mins Maximum: 50 Marks
Answer ALL questions
PART A - (7 X 2 = 14 marks)
What are the statements in JDBC?

 Statement: It can be used for general-purpose access to the database. ...


 PreparedStatement: It can be used when you plan to use the same
1. 2 CO-4 K-1
SQL statement many times. ...
 CallableStatement: CallableStatement can be used when you want to access
database stored procedures.

Compare basic differences between JSP and servlet.

JSP Servlet
JSP is a webpage scripting language Servlets are Java programs that are
that can generate dynamic content. already compiled which also creates
dynamic web content
JSP run slower compared to Servlet as Servlets run faster compared to JSP.
2. it takes compilation time to convert 2 CO-4 K-4
into Java Servlets.
It’s easier to code in JSP than in Java Its little much code to write here.
Servlets.
The advantage of JSP programming There is no such custom tag facility in
over servlets is that we can build servlets.
custom tags which can directly call
Java beans.

What is the purpose of XSLT?


3. 2 CO-4
XSLT (eXtensible Stylesheet Language Transformations) is a language K-1
for transforming XML documents into other XML documents or other formats
such as HTML for web pages, plain text or XSL Formatting Objects.

How to access java bean class? Give example. K-1

JavaBeans are classes that encapsulate many objects into a single object (the bean).
It is a java class that should follow following conventions:
4. 2 CO-4
1. Must implement Serializable.
2. It should have a public no-argument constructor.
3. All properties in java bean must be private with public getters and setter
methods.
// Java program to illustrate the structure of JavaBean class
public classTestBean {
private String name;
public void setName(String name)
{
this.name = name;
}
public String getName()
{
returnname;
}
}

Identify the need for Web Services?

5. Web Services are software systems that are designed to be accessed using web 2 CO-5 K-3
protocols and technologies that are intended to be used by other software
applications rather than directly by end users.
Explain about WSDL?

WSDL is Web Services Definition Language which is based on XML. WSDL


6. defines the web service like operation, parameter, return values and 2 CO-5 K-2
communication protocols.

7. Define service endpoint interface. 2 CO-5 K-1

Service endpoint interface is a Java interface that specifies the operations that will be provided by the
service which is essentially an API for the service.

PART B - (3 X 12 = 36 marks)
8. (a) With suitable example explain how XSLT can be used to transform a document from XML to XHTML.
12 CO-4 K-5
Start with an XML document "cdcatalog.xml" to transform into XHTML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="detail.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
2
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>

Create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template:

The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>.

To get access to the XSLT elements, attributes and features, declare the XSLT namespace at the top of the
document.

The xmlns:xsl="http://www.w3.org/1999/XSL/Transform" points to the official W3C XSLT namespace. While


using this namespace, include the attribute version="1.0" also.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">


<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="aqua">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="artist"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

(b) (i) List and explain the XML syntax rules in detail. 12 CO-4 K-5

XML Syntax Rules


 XML Documents Must Have a Root Element
- XML documents must contain one root element that is the parent of all other elements:
In this example <note> is the root element:
<?xml version="1.0" encoding="UTF-8"?>
<note category ="mail">
<to>Tove</to>
<from>Jani</from>
3
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

 XML DTD

 Document Type Definition purpose is to define the structure of an XML document. It defines the structure
with a list of defined elements in the xml document. 


<!DOCTYPE note

[

 <!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

]> 

where PCDATA refers parsed character data. In the above xml document the elements to, from, heading, body
carries some text, so that, these elements are declared to carry text in DTD file. 
 This definition file is stored
with .dtd extension.
 


 All XML Elements must have a Closing Tag


- An XML element is everything from (including) the element's start tag to (including) the element's end
tag.
An element can contain:
 text
 attributes
 other elements
 or a mix of the above
In the above example:
<to>, <from>, <heading> and <body> have text content because they contain text.
<note> has an attribute (category="email").
 XML Tags are Case Sensitive
- Opening and closing tags must be written with the same case
- <message>This is correct</message>
 XML Elements must be Properly Nested
In HTML, you might see improperly nested elements:
<b><i>This text is bold and italic</b></i>
In XML, all elements must be properly nested within each other:
<b><i>This text is bold and italic</i></b>
 XML Attribute Values must always be Quoted
XML elements can have attributes in name/value pairs just like in HTML.
In XML, the attribute values must always be quoted:
<note date="12/11/2007">
<to>Thamu</to>
<from>Rani</from>
</note>

 Entity References
- Some characters have a special meaning in XML.
4
- If you place a character like "<" inside an XML element, it will generate an error because the parser
interprets it as the start of a new element.
This will generate an XML error:
<message>salary < 1000</message>
To avoid this error, replace the "<" character with an entity reference:
<message>salary &lt; 1000</message>

There are 5 pre-defined entity references in XML:

&lt; < less than

&gt; > greater than

&amp; & ampersand

&apos; ' apostrophe

&quot; " quotation mark

 Comments in XML
The syntax for writing comments in XML is similar to that of HTML:
<!-- This is a comment -->

• CDATA section
– By default, all text inside an XML document is parsed
– You can force text to be treated as unparsed character data by enclosing it in <![CDATA[ ...
]]>
– CDATA means, Character Data defined as blocks of text that are not parsed by the parser, but
are otherwise recognized as markup.
– The entire content of a CDATA section is interpreted as character data, even if it appears to be
markup.
– Begins with <![CDATA[
– Ends with ]]>
– Any characters, even & and <, can occur inside a CDATA
– Whitespace inside a CDATA is (usually) preserved.

<message>
The markup
<![CDATA[
<message>Welcome to XML</message>
]]>
In the above syntax, everything between <message> and </message> is treated as character data and not as
markup.

(b) (ii) Explain about MVC architecture in detail. 12 CO-4 K-5

The following figure illustrates the interaction between Model, View and Controller.

5
MVC Architecture

MVC stands for Model, View and Controller. MVC separates application into three components - Model, View
and Controller.
Model: Model represents shape of the data and business logic. It maintains the data of the application. Model
objects retrieve and store model state in a database.
Model is a data and business logic.
View: View is a user interface. View display data using model to the user and also enables them to modify the
data.
View is a User Interface.
Controller: Controller handles the user request. Typically, user interact with View, which in-turn raises
appropriate URL request, this request will be handled by a controller. The controller renders the appropriate
view with the model data as a response.
Controller is a request handler.

9. (a) Develop an XML document that will hold player(like cricket) collection with field for player-name, age,
batting-average and highest-score. Write suitable DTD and XML schema. 12 CO-4 K-6
In HTML, a browser can check HTML because it knows all about legal HTML.
In XML, user defines what's legal and what's not by specifying the syntax for an XML document.
Document Type Definitions (DTD) provides the original way to validate XML documents, and the syntax for
DTDs is built right in XML 1.0 specification.

Create an external DTD file and its name must be specified in the corresponding XML file. Following
is the DTD file cricketplayer.dtd
<?xml version = "1.0" encoding="UTF-8" ?>
<!DOCTYPE cricketplayer [
<!ELEMENT cricketplayer (player)*>
<!ELEMENT player (playername, age, battingaverage, highestscore)>
<!ELEMENT playername (#PCDATA)>
<!ELEMENT age(#PCDATA)>
<!ELEMENT battingaverage (#PCDATA)>
<!ELEMENT highestscore(#PCDATA)>
]>

Create an XML document player.xml

<?xml version ="1.0" ?>


<!DOCTYPE cricketplayer SYSTEM "cricketplayer.dtd" >
<cricketplayer>
<player>
<playername>MSD </playername>
<age> 38</age>
<battingaverage>40</battingaverage>
<highestscore>140</highestscore>
</player>
6
<player>
<playername>Virat </playername>
<age> 30</age>
<battingaverage>60</battingaverage>
<highestscore>190</highestscore>
</player>
</cricketplayer>

 Just like a DTD, the XML schema is used to describe the structure of an XML document.
 An XML document validated against the XML schema is called “Well Formed”

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


<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"><xs:element name = "cricketplayer">
<xs:complexType>
<xs:sequence>
<xs:element name="player">
<xs:complexType>
<xs:sequence>
<xs:element name = "playername" type = "xs:string" />
<xs:element name = "age" type = "xs:positiveInteger" />
<xs:element name = "battingaverage" type = "xs:integer" />
<xs:element name = "highestscore" type = "xs:integer" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

9.(b) (i) Explain the elements of a SOAP message. 12 CO-5 K-2

A SOAP message is an ordinary XML document containing the following elements −


• Envelope − Defines the start and the end of the message. It is a mandatory element.
• Header − Contains any optional attributes of the message used in processing the message, either at an
intermediary point or at the ultimate end-point. It is an optional element.
• Body − Contains the XML data comprising the message being sent. It is a mandatory element.
• Fault − An optional Fault element that provides information about errors that occur while processing
the message.
General structure of a SOAP message
<?xml version = "1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope"
SOAP-ENV:encodingStyle = "http://www.w3.org/2001/12/soap-encoding">
<SOAP-ENV:Header>

</SOAP-ENV:Header>
<SOAP-ENV:Body>
....
<SOAP-ENV:Fault>

</SOAP-ENV:Fault>
...
</SOAP-ENV:Body>
</SOAP_ENV:Envelope>

7
• The SOAP Envelope element is the root element of a SOAP message. This element defines the XML
document as a SOAP message. The xmlns:soap namespace defines the Envelope as a SOAP Envelope.
The encodingStyle attribute is used to define the data types used in the document.

• The SOAP Header element contains header information. If the Header element is present, it must be the
first child element of the Envelope element.
• The SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the
message.

• The SOAP Fault element holds errors and status information for a SOAP message.

9.(b) (ii) How do you store Java objects? Describe.

• Serialization is the process of translating data structures or object state into a writable byte stream
format that can be stored (for example, in a file or memory buffer) or transmitted (for example, across
a network connection link) and reconstructed later as an actual Java object (possibly in a different
computer environment).
• This process of serializing an object is also called marshalling an object. The opposite operation,
extracting a data structure or object from a series of bytes, is deserialization(also
called unmarshalling).
• This mechanism is used to persist the object.
• A Java object is serializable if its class or any of its superclasses implement either
the java.io.Serializable interface
• The Serializable interface defines no methods; it is simply used to indicate to the Java run-time system
that the class author intends that objects belonging to the class can be serialized.

Advantages of Serialization

1. To save/persist state of an object.


2. To travel an object across a network.
Note:
• If a parent class has implemented Serializable interface then child class doesn’t need to implement it
but vice-versa is not true.
• Only non-static data members are saved via Serialization process since Static data members are not
part of objects of a given class type.

With example program explain

• The ObjectOutputStream class contains writeObject() method for serializing an Object.


• The ObjectInputStream class contains readObject() method for deserializing an object.
• serialVersionUID - explain

10. (a) Discover a JSP code to access a table and records from a student database to obtain the result of a
student. 12 CO-5 K-4
8
 For displaying student mark list. Assume that student information and result is available in a
database which has been stored in a database server.

 Database in MS-Access studentdata with student table having fields studid as Number, Studname as
Text, class as Text, WT as Number, CN as Number, ST as Number, MPMC as Number, ANT as
Number.

 Create a data source name(DSN) as studentDB1for this database.

 Write a jsp coding for fetching student result.

index.html
<HTML>
<HEAD>
<TITLE>Database Lookup</TITLE>
</HEAD>
<BODY>
<H1>Database Lookup</H1>
<FORM ACTION="basic.jsp" METHOD="POST">
Please enter the stud id you want to find to get result: <BR>
<INPUT TYPE="TEXT" NAME="id"><BR>
<INPUT TYPE="SUBMIT" value="Submit">
</FORM>
</BODY>
<HTML>

basic.jsp
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<HTML>
<HEAD>
<TITLE>Fetching Data From a Database</TITLE>
</HEAD>
<BODY>
<H1>Fetching Student result from the Database</H1>
<%
Connection connection=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:studentDB1";
connection = DriverManager.getConnection(url," "," ");
Statement statement = connection.createStatement();
String id = request.getParameter("id");
9
ResultSet resultset = statement.executeQuery("select * from student where studid = ' " + id + " ' ");
if(!resultset.next())
{
out.println("Sorry, could not find that student. ");
}
else
{
%>
<TABLE BORDER="1">
<TR>
<TH>ID</TH>
<TH>Student Name</TH>
<TH>Class</TH>
<TH>WT</TH>
<TH>CN</TH>
<TH>ST</TH>
<TH>MPMC</TH>
<TH>ANT</TH>
</TR>
<TR>
<TD><%= resultset.getString(1) %></TD>
<TD><%= resultset.getString(2) %></TD>
<TD><%= resultset.getString(3) %></TD>
<TD><%= resultset.getString(4) %></TD>
<TD><%= resultset.getString(5) %></TD>
<TD><%= resultset.getString(6) %></TD>
<TD><%= resultset.getString(7) %></TD>
<TD><%= resultset.getString(8) %></TD>
</TR>
<%
}
resultset.close();
statement.close();
connection.close();
%>
</TABLE>
<BR>
<%
}

10
%>
</BODY>
</HTML>

10 (b) i) Discuss AJAX architecture and compare it with traditional web application architecture.
12 CO-5 K-6

 Asynchronous Javascript and XML is a client side techniques that combines a set of known
technologies in order to create faster and more user friendly web pages.
 User sends a request to server and continue interaction with the web page without waiting for server
response. Once the response arrives, a designated area in UI will update itself and reflect the response
information. Whole page need not be reloaded.

Ajax Architecture

XMLHttpRequest object plays a important role.


• User sends a request from the UI and a javascript call goes to XMLHttpRequest object.
• HTTP Request is sent to the server by XMLHttpRequest object.
• Server interacts with the database using JSP, PHP, Servlet, ASP.net etc.
• Data is retrieved.
• Server sends XML data or JSON data to the XMLHttpRequest callback function.
• HTML and CSS data is displayed on the browser.

Sl.no. Traditional Web Application Architecture Ajax based web application architecture.
1 At the client side the browser client has only At the client side the browser client has user
one component and that is user interface. interface and AJAX Engine due to which client
gets quick response from the server
2. It makes use of Synchronous It makes use of asynchronous communication.
communication. The client has to wait to get By adding new layer of AJAX Engine at the
the response from the server then only client client side, it eliminates start-stop-start-stop kind
can make the request to the server. It is of communication.
start-stop-start-stop kind of communication.
3 It is less responsive It is more responsive
4 User cannot get rich user interface User gets rich UI experience with ajax
experience architecture
5 Limited use of javascript, CSS and XML Ajax incorporates several technologies
technologies. Most user action in the
interface trigger an HTTP rewuest back to a  standards-based presentation using
web server. XHTML, CSS
 dynamic display and interaction using

11
DOM
 data interchange and manipulation using
XML
 asynchronous data retrieval using
XMLHttpRequest
 and JavaScript binding everything
together.

ii) Explain about the XMLHttpRequest Object in detail.

 The XMLHttpRequest object allows client-side JavaScript to make HTTP requests (both GET and
POST) to the server without reloading pages in the browser.
 This JavaScript object was originally introduced in Internet Explorer 5 by Microsoft and it is the
enabling technology that allows asynchronous requests
 By performing screen updates on the client, you have a great amount of flexibility when it comes to
creating your Web site :
 Eliminate page refreshes every time there is user input
 Edit data directly in place, without requiring the user to navigate to a new page to edit the data
 Increase site performance by reducing the amount of data downloaded from the server

XMLHttpRequest object performs following operations:


• Sends data from the client in the background
• Receives the data from the server
• Updates the webpage without reloading it.
Methods:
Open(“method”,”url”,boolean)
 to send a request to server
 method - GET or POST
 url - address of the target file
 boolean - to denote whether the request is synchronous or asynchronous. If true, asynchronous.
Send(content)
 to send data to server for processing
 content - may be string or DOM type of document.

Properties:
 readystate
- used to identify the state of the request. Possible values 0-4.
- 0 UNOPENED open() is not called.
- 1 OPENED open is called but send() is not called.
- 2 HEADERS_RECEIVED send() is called, and headers and status are available.
- 3 LOADING Downloading data; responseText holds the data.
- 4 DONE The operation is completed fully.
 onreadystatechange
- It is called whenever readystate attribute changes. It must not be used with synchronous
requests.
 status
• -Numeric code return by server.Eg.404,200
 responseText
- the string data returned by the server process.
 responseXML
- the DOM type of document returned by the server process.

12
Example:
CREATE XMLHTTPREQUEST OBJECT
<html>
<head>
<script type="text/javascript">
function fun1()
{
var request;
if (window.ActiveXObject)
{
/*supported in IE*/
request = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
/* supported in Safari and Mozilla*/
request = new XMLHttpRequest();
}
else
{
request = null; }

req.onreadystatechange=function()
{
if (req.readyState==4 && req.status==200)
{
document.getElementById("myDiv").innerHTML=req.responseText;
}
}
req.open("POST",”welcome.html",true);
req.send();
} // fun1() close
</script>
</head>
<body>
<button type="button" onclick="fun1()">Change Content</button><br><br>
<div id="myDiv">Click on the button above, this text can be changed</div>
</body>
</html>

Faculty ***** HOD

13

You might also like