Register No.
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)
1.
What is MVC paradigm?
The Model View Controller (MVC) design pattern specifies that an application
consist of a data model(model), presentation information(view), and control
information(controller).
2 CO-4
K-1
2.
Discuss CDATA and PCDATA.
PCDATA - Parsed Character Data
PCDATA is text that will be parsed by a parser. Tags inside the text will be
treated as markup and entities will be expanded.
CDATA - (Unparsed) Character Data
CDATA is text that will not be parsed by a parser. Tags inside the text
will not be treated as markup and entities will not be expanded.
2 CO-4
K-6
3.
What is a well-formed XML document?
A well-formed document in XML is a document that "adheres to
the syntax rules specified by the XML 1.0 specification in that it must
satisfy both physical and logical structures".
At its base level well-formed documents require that:
Content be defined.
Content be delimited with a beginning and end tag
Content be properly nested (parents within roots, children within
2 CO-4
K-1
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
2
parents)
4.
Identify the need of UDDI?
Universal Description, Discovery and Integration (UDDI) is a directory
service where businesses can register and search for Web services.
UDDI is a platform-independent framework for describing services,
discovering businesses, and integrating business services by using the
Internet.
It is a directory for storing information about web services by WSDL. It
communicates via SOAP.
2 CO-5
K-3
5.
How can the user-defined simple types be defined?
The user-defined simple types can be defined by specifying one or more
restrictions on the values of a simple built-in type.
All built-in data type has various facets that can be used within a restriction
to form a simple user- defined type such as base, enumeration, length,
minLength, maxLength, minInclusive, maxInclusive etc
Ex:<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
2 CO-5
K-1
6.
Define Serialization.
Serialization is the process of writing the state of the object to the byte
stream. This technique is useful when we want to store the current state of
the object to the file.
2 CO-5
K-1
7. Explain the tools available in JWSDP 1.3? 2 CO-5 K-2
Web services can be built using two tools.
wscompile: converts Java files into a WSDL document along with another intermediate output file.
3
wsdeploy: is used to package our service before finally deploying it as a web application.
PART B - (3 X 12 = 36 marks)
8. (a) Develop a CD catalog (title, artist, country, company, price, year) using XML and transform this XML
into XHTML using XSLT? 12 CO-4 K-6
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>
<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>
4
<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) Explain about DOM based XML processing. 12 CO-4 K-5
DOM defines a standard for accessing and manipulating XML documents.
All XML elements can be accessed through the XML DOM.
The XML DOM is:
• A standard object model for XML
• A standard programming interface for XML
• Platform- and language-independent
• A W3C standard
In other words: The XML DOM is a standard for how to get, change, add, or delete XML elements.
According to the DOM, everything in an XML document is a node. It considers
• The entire document is a document node
• Every XML element is an element node
• The text in the XML elements are text nodes
• Every attribute is an attribute node
• Comments are comment nodes
• All nodes can be accessed through the tree.Their contents can be modified or deleted, and new elements can
be created.
• The tree structure contains root (parent) elements, child elements and so on.
• By using tree structure, you can get to know all succeeding branches and subbranches starting from the root.
Parsing using DOM (tree based)
JAXP is a tool, stands for Java API for Xml Processing, used for accessing and manipulating xml document in
a tree based manner.
In this approach, to access XML document, the document object model implementation is defined in the
following packages:
javax.xml.parsers
org.w3c.dom
The following DOM javaClasses are necessary to process the XML document:
DocumentBuilderFactory class creates the instance of DocumentBuilder.
5
DocumentBuilder produces a Document (a DOM) that conforms to the DOM specification
The following methods and properties are necessary to process the XML document:
Property Meaning
nodeName Finding the name of the node
nodeValue Obtaining value of the node
parentNode To get parent node
childNodes Obtain child nodes
attributes For getting the attributes values
Method Meaning
getElementByTagName(name)
To access the element by
specifying its name
appendChild(node) To insert a child node
removeChild(node)
To remove existing child node
Example
The following example (Parsing_DOMDemo.java) parses an XML document ("student1.xml") into an XML
DOM object and then checks well formedness of XML document using DOM API.
Parsing_DOMDemo.java:
import java.io.*;
importjavax.xml.parsers.*;
import org.w3c.dom.*;
importorg.xml.sax.*;
public class Parsing_DOMDemo
{
static public void main(String[] arg)
{
try
{
System.out.print("Enter the name of XML document: ");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String file_name = input.readLine();
File fp = new File(file_name);
DOM API is defined in the package org.w3c.dom.*
Using this API a DOM object tree is created from the
input XML document and this tree helps in parsing the
XML document.
6
if(fp.exists())
{
try
{
DocumentBuilderFactoryFactory_obj = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = Factory_obj.newDocumentBuilder();
InputSourceip_src = new InputSource(file_name);
Document doc = builder.parse(ip_src);
System.out.println(file_name + " is well-formed!");
}
catch (Exception e)
{
System.out.println(file_name + " isn't well-formed!");
System.exit(1);
}
}
else
{
System.out.print("File not found!");
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
student1.xml:
<?xml version="1.0"?>
<student>
<name>Santhosh</name>
javax.xml.parsers.* provides classes such as DocumentBuilder and DocumentBuilderFactory for
processing of XML documents.
Package org.xml.sax provides the core SAX(Simple API for XML) APIs. The SAX parser will use the
InputSource object to determine how to read XML input. If the file you want to parse makes reference
to an external DTD or any external entities by relative URIs then you can't parse it from a
plain InputStream, as the parser doesn't know the base URL it should use to resolve these relative paths.
In that case you will need to construct an InputSourcefrom the stream.
DocumentBuilderFactory is an API which produces DOM object tree from the given XML document.
Using the object of DocumentBuilderFactory an instance of DocumentBuilder is created to invoke parse
method.
parse method takes XML document as an input, parses it. If the XML document is well formed ie if
every starting tag has an ending tag then appropriate message will be displayed.
7
The diagram here shows the JAXP APIs to process xml document using the DOM parser:
9. (a)Design an XML document that will hold student collection with field for studentname, department,
registernumber and cgpa. 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 student.dtd
<?xml version = "1.0" encoding="UTF-8" ?>
<!DOCTYPE studentinfo [
<!ELEMENT studentinfo (student)*>
<!ELEMENT student (studentname, department, registernumber, cgpa)>
<!ELEMENT studentname (#PCDATA)>
<!ELEMENT department(#PCDATA)>
<!ELEMENT registernumber(#PCDATA)>
<!ELEMENT cgpa(#PCDATA)>
] >
Create an XML document player.xml
<?xml version ="1.0" ?>
<!DOCTYPE studentinfo SYSTEM "student.dtd" >
<studentinfo>
<student>
< studentname>Keerthi</ studentname>
<department> IT</department>
<registernumber>71331840</registernumber>
<cgpa>9.1</cgpa>
</ student>
<student>
< studentname>Elakkia</ studentname>
<department> IT</department>
<registernumber>71331809</registernumber>
<cgpa>9.3</cgpa>
</ student>
</studentinfo>
8
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 = "studentinfo">
<xs:complexType>
<xs:sequence>
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name = "studentname" type = "xs:string" />
<xs:element name = "department" type = "xs:string" />
<xs:element name = "registernumber" type = "xs:string" />
<xs:element name = "cgpa" type = "xs:float" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
(b) i) What do you mean by AJAX? Write the advantages of AJAX. 12 CO-5 K-2
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.
Advantages:
• Helps to build fast, dynamic websites.
9
• Ajax allows to perform processing on client computer (in JavaScript) with data taken from the server
thereby reducing server load by moving a part of server functionality to client side.
• Ajax can selectively modify a part of a page displayed by the browser, and update it without the need to
reload the whole document with all images, menus etc. This bridges the gap between desktop and web
applications.
• Saves bandwidth by only transmitting new information
• Creates possibility of entirely new types of user interfaces not possible in traditional model.
ii) Explain in detail the steps involved in writing a web service. 12 CO-5 K-2
To write web service using JAX-RPC, one need JWSDP(Java Web Server Development Package). This
package has wscompile and wsdeploy tools. wscompile is used to convert java file into wsdl file whereas
wsdeploy is used to package web service.
These are the basic steps for creating the web service and client:
Step 1:Create a service end point interface - The service endpoint interface (SEI) is a Java interface class that
defines the methods to be exposed as a Web service.
Rules for creating service end point interface are as follows:
1. The interface must extend java.rmi.Remote interface
2. Every method in this interface must throw java.rmi.Remote exception
3. Every method return type and its parameter data type in this interface must be java primitive data
types
4. The interface must not contain any public static final declarations.
Step 2: Code the implementation class.
Step 3: Compile using javac to create respective classes
Step 4: Use wscompile to generate wsdl doc.
Inputs to wscompile are supplied via the following configuration file called config.xml file.
wscompile –define – d WEB-INF –classpath WEB-INF/classes – model WEB-INF/model.xml.gz config.xml
Step 5: Create another configuration file called jaxrpc-ri.xml which is used as deployment descriptor file.
Step 6: Package and deploying the web service created
Create WAR(Web Archive) file. Add the deployment descriptor and service files to the WAR file. The
following command is used:
jar cf converter-temp.war WEB-INF
Deploy the war file using the following command
wsdeploy –o converter.war converter-temp.war
Step 7: Create a client file to access the web service
Step 8: Use wscompile to generate and compile the web service artifacts needed to connect to the service.
wscomplie –gen –keep –d classes –s src config.xml
This instructs to generate a class file from the wsdl and keep the java source file in src folder.
10
Step 9: Compile the client class.
Step 10: Run the client.
10.(a) Develop a JSP code to conduct online exam, update result in database table and obtain the result of a
student in the web page. 12 CO-5 K-4
1. Create a database in MS-Access. Example studentDB database with student table having fields Seat_no
as Number, Studname as Text, Marks as Number.
2. Create a data source name(DSN) for this database. Go to control panel, Adminstrative tools, Data
Source(ODBC), System DSN tab, Add button, Choose driver as Microsoft Access Driver(*.mdb,
*.accdb), Finish button.
3. Give Data Source Name as studentDB1 and click Select button under Database group and select the
database student .accdb which has been created already and click ok.
4. Now open Notepad and wite your jsp coding for conducting online examination.
5. Save this file in the location c:\apache tomcat directory\webapps\jspexample\OnlineExam.jsp
6. Start running apache tomcat server
7. Open the web browser and execute the JSP program by typing the URL http://
localhost:9999/jspexample/OnlineExam.jsp
8. Take online exam and submit. Results will be displayed immediately. You can go to your MS-Access
database studentDB1 and student table gets updated.
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%
String SeatNum,Name;
String ans1,ans2,ans3,ans4,ans5;
int a1,a2,a3,a4,a5;
a1=a2=a3=a4=a5=0;
Connection connect=null;
Statement stmt=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:studentDB1";
connect = DriverManager.getConnection(url," "," ");
if(request.getParameter("action")!=null)
{
SeatNum = request.getParameter("Seat_no");
Name = request.getParameter("Studname");
ans1 =request.getParameter("group1");
if(ans1.equals("True"))
a1=2;
else
a1=0;
ans2 = request.getParameter("group2");
if(ans2.equals("True"))
a2=0;
else
a2=2;
ans3 = request.getParameter("group3");
if(ans3.equals("True"))
a3=0;
11
else
a3=2;
ans4 = request.getParameter("group4");
if(ans4.equals("True"))
a4=2;
else
a4=0;
ans5 = request.getParameter("group5");
if(ans5.equals("True"))
a5=0;
else
a5=2;
int Total=a1+a2+a3+a4+a5;
stmt = connect.createStatement();
String query = "INSERT INTO student (" + "Seat_no,Studname,Marks" + ") VALUES ('" +SeatNum + "', '" +
Name + "', '"+Total+ "')";
int result = stmt.executeUpdate(query);
stmt.close();
stmt = connect.createStatement();
query = "SELECT * FROM student WHERE Studname="+"'"+Name+"'";
rs = stmt.executeQuery(query);
%>
<html><head><title>Student Mark List</title></head>
<body bgcolor=Silver>
<center>
<h2>Students Marksheet</h2>
<h3>Name of the College : SNS College of Engineering</h3>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>Seat_No</b></td>
<td><b>Studentname</b></td>
<td><b>Marks</b></td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
</tr>
<%
}
rs.close();
stmt.close();
connect.close();
%>
</table>
</center>
<br/><br/><br/>
<table>
<tr><td><b>Date:<%=new java.util.Date().toString() %></td></tr>
<tr><td><b>Signature: X.Y.Z. <b></td></tr>
</table>
12
<div>
<a href="http://localhost:9999/jsp-examples/OnlineExam.jsp">Click here to go back
</body>
</html>
<%}else{%>
<html>
<head><title>Online Examination</title>
<script language="javascript">
function validation(Form_obj)
{
if(Form_obj.Seat_no.value.length==0)
{
alert("Please,fill up the Seat Number");
Form_obj.Seat_no.focus();
return false;
}
if(Form_obj.Studname.value.length==0)
{
alert("Please,fill up the Name");
Form_obj.Studname.focus();
return false;
}
return true;
}
</script>
</head>
<body bgcolor=silver>
<center>
Online Examination
</center>
<form action="OnlineExam.jsp" method="post" name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<hr/>
<table>
<tr>
<td>
Seat Number : </td>
<td><input type="text" name="Seat_no"></td>
</tr>
<tr>
<td>
Name : </td>
<td><input type="text" name="Studname" size="50"></td>
</tr>
<tr>
<td><b>Total Marks:5*2=10 </b></td>
<td></td><td></td><td></td><td><b>Time: 05 Mins.</b></td>
</tr>
</table>
<hr/>
<b>1. XML enables you to collect information once and reuse it in a variety of ways.</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<br/>
<b>2. In Modern PC there is no cache memory.</b><br/>
13
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<br/>
<b>3. JavaScript functions cannot be used to create script fragments
that can be used over and over again</b><br/>
<input type="radio" name="group3" value="True">True
<input type="radio" name="group3" value="False">False<br>
<br/>
<b>4.The DriverManager class is used to open a connection to a database via
a JDBC driver.</b><br/>
<input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>
<br/>
<b>5. The JDBC and ODBC does not share a common parent</b><br/>
<input type="radio" name="group5" value="True">True
<input type="radio" name="group5" value="False">False<br>
<hr/>
<center>
<input type = "submit" value="Submit">
<input type = "reset" value="Clear"><br><br>
</center>
</form>
<%}%>
(b) i) Explain how the callback function is written as an anonymous function or a named function in the request
phase function. 12 CO-5 K-2
• Callback functions are used to handle responses from the server in Ajax.
• A callback function can be either a named function or an anonymous function.
• Follow the steps below to create and use the different kinds of callback functions.
Write a callback function as an anonymous function
Set the value of an event handler onreadystatechange equal to the anonymous function.
req.onreadystatechange=function()
{
if (req.readyState==4 && req.status==200)
{
document.getElementById("myDiv").innerHTML=req.responseText;
}
}
Write a callback function as a named function
1. Create an XMLHttpRequest object in the global scope
var req = new XMLHttpRequest();
2. Write a function to use as the callback function.
function myCallBack()
{
if (req.readyState==4 && req.status==200)
{ console.log(req.responseText); }
}
3. Set the value of the onreadystatechange property to the name of the function.
req.onreadystatechange=myCallBack;
14
ii) What is WSDL? Describe the structure of the WSDL document in detail. 12 CO-5 K-2
WSDL is an XML format for describing web service interface. WSDL file defines set of operations permitted
on the server and format that client must follow while requesting service. WSDL file acts like contract between
client and service for effective communication between two parties. Client has to request service by sending
well formed and conformant SOAP request.
WSDL Document:
WSDL document uses the following elements in the definition of network services:
Data types − The data types to be used in the messages are in the form of XML schemas (such as
XSD).
Message– an abstract definition of the data being communicated.
Operation– an abstract description of an action supported by the service.
Port Type–an abstract set of operations supported by one or more endpoints.
Binding– a concrete protocol and data format specification for a particular port type.
Port– a single endpoint defined as a combination of a binding and a network address.
Service– a collection of related endpoints.
The WSDL Document Structure
The main structure of a WSDL document looks like this −
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
<operation>
definition of a operation.......
</operation>
</portType>
<binding>
definition of a binding....
</binding>
<service>
definition of a service....
</service>
</definitions>
Faculty ***** HOD