CIA I Answer Key Remedial
CIA I Answer Key Remedial
Course Code & Title: CCS375 & WEB TECHNOLOGIES Batch: 2021-25
CO1 Construct a basic website using HTML and Cascading Style Sheets
Build dynamic web page with validation using Java Script objects and by applying
CO2
different event handling mechanisms.
CO3 Develop server side programs using Servlets and JSP.
CO4 Construct simple web pages in PHP and to represent data in XML format.
CO5 Develop interactive web applications
Answer all questions
6.a. Draw the structure of HTTP request and response message and explain them in detail. CO1 / U
HTTP Request Message
The following are the parts of the HTTP request message:
Request-Line or Start line: This begins with a method token, followed by the Request-URI and the
protocol version, and ending with CRLF (Carriage Return and Line Feed). The elements are separated
by space.
Request Method: This indicates the method to be performed on the resource identified by the given
Request-URI. The method is case-sensitive and should always be mentioned in uppercase. The following
are the methods:
GET - return the resource specified by the Request-URI as the body of a response message.
POST- pass the body of this request message on as data to be processed by the resource specified by
the Request-URI.
HEAD- return the same HTTP header fields that would be returned if a GET method were used, but
not return the message body that would be returned to a GET (this provides information about a
resource without the communication overhead of transmitting the body of the response, which
may be quite large).
OPTIONS- return (in Allow header field) a list of HTTP methods that may be used to access the
resource specified by the Request-URI.
PUT- store the body of this message on the server and assign the specified Request-URI to the
data stored so that future GET request messages containing this Request-URI will receive this data in
their response messages.
DELETE- respond to future HTTP request messages that contain the specified Request- URI with a
response indicating that there is no resource associated with this Request-URI.
TRACE- return a copy of the complete HTTP request message, including start line, header fields,
and body, received by the server. Used primarily for test purposes.
(Or)
6.b. i) Explain the types of selectors in CSS with example. (5) CO1/U
The CSS element Selector
The element selector selects HTML elements based on the element name.
p{
text-align: center;
color: red;
}
The CSS id Selector
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the element.
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
The CSS Universal Selector
The universal selector (*) selects all HTML elements on the page.
The grouping selector selects all the HTML elements with the same style definitions.
Look at the following CSS code (the h1, h2, and p elements have the same style definitions):
ii) Illustrate about transitions and animations in CSS with an example. (5)
CSS Transitions:
CSS transitions provide a way to control animation speed when changing CSS properties.
Instead of having property changes take effect immediately, the transition cause the changes in a
property to take place over a period of time. To create a transition effect, you must specify two things:
1. the CSS property you want to add an effect to
2. the duration of the effect. If the duration part is not specified, the transition will have no
effect, because the default value is 0.
transition-property: Specifies the name or names of the CSS properties to which transitions should
be applied. Only properties listed here are animated during transitions; changes to all other properties
occur instantaneously as usual.
transition-duration: Specifies the duration over which transitions should occur. You can specify a
single duration that applies to all properties during the transition, or multiple values to allow each
property to transition over a different period of time.
CSS Animations
CSS animations make it possible to animate transitions from one CSS style configuration to another.
Animations consist of two components, a style describing the CSS animation and a set of keyframes that
indicate the start and end states of the animation’s style, as well as possible intermediate waypoints
Letting the browser control the animation sequence lets the browser optimize performance
and efficiency.
Keyframes are used to create animations. The @keyframes CSS at-rule controls the
intermediate steps in a CSS animation sequence by defining styles for keyframes along the
animation sequence. This gives more control over the intermediate steps of the animation
sequence than transitions. The sub-properties of the animation property are:
Animation-name
Animation-duration
Animation-timing function
Animation-delay
Animation-iteration count
7.a. i) Write a javascript to demonstrate the usage of form validation. (5)
CO2/U
Form validation occurs at the server, after the client had entered all necessary data and
(May 22)
then pressed the Submit button. If some of the data that had been entered by the client had
been in the wrong form or was simply missing, the server would have to send all the data
back to the client and request that the form be resubmitted with correct information. This is a
lengthy process and over burdening server. JavaScript, provides a way to validate form's data
on the client's computer before sending it to the web server. Form validation generally
performs two functions:
Basic Validation - Checking the form to make sure that the data entered is right.
Data Format Validation – Checking the data entered in the form for right value.
(Or)
7.b. Write a program using HTML 5 for creating client-side image map. CO2/U
main.html (May 22)
<html>
<head>
<BODY bgcolor="#gop6876cgdt5564ss">
<img src ="indiamap.jpeg" usemap="#indiamap" />
<map name=indiamap>
<area shape="circle" coords="500,1092,15" href="tamilnadu.html" alt="Tamilnadu">
<area shape="rect" coords="376,1076,406,1100" href="karnataka.html" alt="Karnataka">
</map>
</head>
</BODY>
</html>
tamilnadu.html
<html>
<head><title>Tanil Nadu - India</title></head>
<body bgcolor="palegreen">
<h1><center>Tamil Nadu</center></h1>
<h3>is one of the 29 states of India. Its capital and largest city is Chennai.
Tamil Nadu lies in the southernmost part of the Indian Peninsula and
is bordered by the States of puducherry, Kerala, Karnataka, Andha Pradesh.
</h3>
<h3>
<ul>
<li>Districts<i> - 33</i>
<li>Capital City<i> - Chennai</i>
<li>Largest City<i> - Chennai</i>
<li>Governor<i> - R.N.Ravi</i>
<li>Chief Minister<i> - M.K.Stalin </i>
<li>Population<i> - 72,147,030</i>
<li>Tourist spots<i> - Mamallapuran, Ooty, Kodaikanal, Marina,
Mudurai Meenakshi Amman Temple, Thanjavur etc.,</i>
</ul>
<a href="main.html">back</a>
</body>
</html>
karnataka.html
<html>
<head><title>Karnataka - India</title></head>
<body bgcolor="wheat">
<h1><center>Karnataka</center></h1>
<h3>
<ul>
<li>Districts<i> - 30</i>
<li>Capital City<i> - Bangalore</i>
<li>Largest City<i> - Bangalore</i>
<li>Governor<i>- Thawar Chand Gehlot</i>
<li>Chief Minister<i> Basavaraj Bommai </i>
<li>Population<i> - 61,130,704</i>
<li>Tourist spots<i> - Gol Gumbaz, Mysore Palace, Keshava Temple etc.,</i>
</ul>
</h3>
<a href="main.html">back</a>
</body>
</html>
CO3/U
8.a. Sketch the life cycle of java servlets and explain them in detail
In the life cycle of servlet there are three important methods. These methods are
i) init()
ii) service()
iii) destroy()
init()
The life cycle of servlet begins here
This method is called only once
It is not called again for each user request
The init() method simply creates or loads some data that will be used throughout the
life of the servlet.
Syntax:
public void init() throws ServletException {
// Initialization code...
}
service()
Handles all the request sent by the client
It is called only after the servlet is initialized
It is the main method to perform the actual task
This service() method then involves doGet(), doPost() etc. methods.
Syntax:
public void service (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Servlet code
}
doGet()
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Servlet code
}
doPost()
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Servlet code
}
destroy()
The end of the servlet life is indicated by this method
It is called only once
All the resources initialized for servicing the request are cleaned up
Syntax:
(Or)
8.b. Write a servlet program to get username and password and to display the result. Use CO3 /A
validation and exception handling whenever required
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class JDBCServlet extends HttpServlet
{
public void doGet(HttpServletRequest inRequest,HttpServletResponse outResponse)
throws ServletException,IOException
{
PrintWriter out = null;
Connection connection = null;
Statement statement;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
connection =DriverManager.getConnection("jdbc:mysql://localhost/products");
statement = connection.createStatement();
outResponse.setContentType("test/html");
out = outResponse.getWriter();
rs = statement.executeQuery("SELECT ID, title, price FROM product");
out.println("<HTML><HEAD><TITLE>Products</TITLE></HEAD>");
out.println("<BODY>");
out.println("<UL>");
while (rs.next()) {
out.println("<LI>" + rs.getString("ID") + " " + rs.getString("title")+ " " +rs.getString("price"));
}
out.println("</UL>");
out.println("</BODY></HTML>");
}
catch (ClassNotFoundException e)
{
out.println("Driver Error");
} catch (SQLException e)
{
out.println("SQLException: " + e.getMessage());
}
}
public void doPost(HttpServletRequest inRequest,HttpServletResponse outResponse) throws
ServletException, IOException
{
doGet(inRequest, outResponse);
}
}
?>
strtoupper() It returns the <?php GEEKSFORGEEKS
& string after
$str = "GeeksForGeeks"; Geeksforgeeks
strtolower() converting all the echo strtoupper($str)."<br>";
letters to echo strtolower($str);
uppercase
?>
It returns the
string after
converting all the
letters to
lowercase.
str_split() It returns an <?php Array (
array containing
$str = "GeeksForGeeks"; [0] => G
parts of the print_r(str_split($str));
string. echo "<br>"; [1] => e
Syntax: print_r(str_split($str, 3));
str_split(string, [2] => e
length) ?>
[3] => k
[4] => s
[5] => F
[6] => o
[7] => r
[8] => G
[9] => e
[10] => e
[11] => k
[12] => s
)
Array (
[0] => Gee
[1] => ksF
[2] => orG
[3] => eek
[4] => s
)
trim() This function <?php : PHP
eliminates the $str=“PHP ”;
echo"<h3>:$str</h3>”; : PHP
white space from
both ends of the echo"<h3>:”.trim($str);
string echo"</h3>”;
?>
(Or)
9.b. Illustrate the merits and demerits of DOM and SAX parser with neat examples. CO4 /
AN (Dec
DOM vs SAX
22)
SAX DOM
SAX is Simple API for XML Document Object Model (DOM) API
The ng-switch directive lets you hide/show HTML elements depending on an expression.
Child elements with the ng-switch-when directive will be displayed if it gets a match, otherwise the
element, and its children will be removed.
You can also define a default section, by using the ng-switch-default directive, to show a section if
none of the other sections get a match.
Syntax
<element ng-switch="expression">
<element ng-switch-when="value"></element>
<element ng-switch-when="value"></element>
<element ng-switch-when="value"></element>
<element ng-switch-default></element>
</element>
<div ng-switch="myVar">
<div ng-switch-when="dogs">
<h1>Dogs</h1>
<p>Welcome to a world of dogs.</p>
</div>
<div ng-switch-when="tuts">
<h1>Tutorials</h1>
<p>Learn from examples.</p>
</div>
<div ng-switch-when="cars">
<h1>Cars</h1>
<p>Read about cars.</p>
</div>
<div ng-switch-default>
<h1>Switch</h1>
<p>Select topic from the dropdown, to switch the content of this DIV.</p>
</div>
</div>
(Or)
10. Discuss in detail about node JS and react JS with neat architecture. CO5/
b U
ReactJS is an open source, component-based front end Java Script library maintained by
Facebook
This library is responsible only for the view layer of the application. That means this
JavaScript is for building user interfaces.
Features of ReactJS
JSX
JSX stands for JavaScript XML. It is a JavaScript syntax extension.
Its an XML or HTML like syntax used by ReactJS.
Components
ReactJS is all about components.
ReactJS application is made up of multiple components, and each component has
its own logic and controls.
If you have npx and Node.js installed, you can create a React application by using create-react-app.
cd my-react-app
npm start
A new browser window will pop up with your newly created React App! If not, open your browser and
type localhost:3000 in the address bar.
Node JS
NodeJS is an open source technology for servers.
Using Node.js we can run JavaScript on the server.
It runs on various platforms such as Windows, Linux, Unix and MacOS.
Uses of Node.js
1. It can create, open, read, delete, write and close files on the server.
2. It can collect form data.
3. It can also add, delete, modify data in databases.
4. It generates dynamic web pages.
Features
Extremely fast: Node.js is built on Google Chrome's V8 JavaScript Engine, so its library
is very fast in code execution.
Single threaded: Node.js follows a single threaded model with event looping.
Highly Scalable: Node.js is highly scalable because event mechanism helps the server to
respond in a non-blocking way.
No buffering: Node.js cuts down the overall processing time while uploading audio and
video files. Node.js applications never buffer any data. These applications simply output
the data in chunks.
Open source: Node.js has an open source community which has produced many excellent
modules to add additional capabilities to Node.js applications.
License: Node.js is released under the MIT license.
Environment
For executing the Node.js scripts we need to install it. We can get it downloaded from
https://nodejs.org.en
After successful installation we can now execute the Node.js document. The Node.js file
has extension .js
Following is a simple node.js program which can be written in notepad.
File: console_example1.js
console.log('Hello JavaTpoint');
node console_example1.js