We Nov Dec - 2024
We Nov Dec - 2024
4. State the commands in cascading style sheet used for grouping of elements. [UN]
A CSS class is typically used to apply a style to a group of elements on a web page, while IDs are
usually reserved for unique elements. This makes option A correct: to style a group of elements, you'd use a
CSS class.
Grouping ID Selectors: You can also group ID selectors using commas. However, it's uncommon to use
multiple IDs in a group because IDs should ideally be unique within a document.
Syntax
#id1, #id2 {
property: value;
}
Ex:
#header, #footer {
background-color: #333;
color: white;
}
In JavaScript, event handling enables web developers to create interactive, dynamic web applications
by allowing specific functions to be executed when certain actions occur.
PART-B (5 x 13 = 65 Marks)
11. a) Explain in detail about web protocols used for communication in Internet with
neat diagram. [UN] (13)
TCP protocol:
It is a connection oriented protocol and offers end to end packet delivery. It acts as back bone of the
connection.
Features:
· Stream data transfer
· Reliability
· Full duplex operation
· It transmit the bytes not acknowledged within specific time period.
Services:
· Stream delivery service
· Sending and receiving buffers
· Bytes and segments
· Full duplex services
· Connection oriented services
IP Protocol:
IP Protocol is a connectionless and unreliable protocol. It ensures no guarantee of successfully transmission
of data. In order to make it reliable, it must pair with TCP at transport layer like TCP/IP. The length of
datagram is available.
The datagram is divided into 2 parts
Header
Data Header
HTTP (Hyper Text Transfer Protocol)
This protocol is used to transfer hypertexts over the internet and it is defined by the www(world wide
web) for information transfer. This protocol defines how the information needs to be formatted and
transmitted. And, it also defines the various actions the web browsers should take in response to the calls
made to access a particular web page.
FTP (File Transfer Protocol)
This protocol is used for transferring files from one system to the other. This works on a client-server
model. When a machine requests for file transfer from another machine, the FTO sets up a connection
between the two and authenticates each other using their ID and Password. And, the desired file transfer takes
place between the machines.
SMTP (Simple Mail Transfer Protocol)
These protocols are important for sending and distributing outgoing emails. This protocol uses the
header of the mail to get the email id of the receiver and enters the mail into the queue of outgoing mail. And
as soon as it delivers the mail to the receiving email id, it removes the email from the outgoing list.
OR
b) Discuss in detail about the working principle of a website. [UN] (13)
Website Purpose
There are many different purposes that websites may have but there are core purposes common to all
websites;
Describing Expertise
Building Your Reputation
Generating Leads
Sales and After Care
Simplicity
Simplicity is the best way to go when considering the user experience and the usability of your website.
Below are ways to achieve simplicity through design.
Color
Type
Imaginary
Navigation
Navigation is the way finding system used on websites where visitors interact and find what they are
looking for. Website navigation is key to retaining visitors. If the website navigation is confusing visitors
will give up and find what they need elsewhere. Keeping navigation simple, intuitive and consistent on
every page is key.
F-Shaped Pattern Reading
The F- based pattern is the most common way visitors scan text on a website. Eye-tracking studies
have found that most of what people see is in the top and left areas of the screen. The F shaped layout mimics
our natural pattern of reading in the West (left to right and top to bottom). An effectively designed website
will work with a reader’s natural pattern of scanning the page.
Visual Hierarchy
Visual hierarchy is the arrangement of elements in order of importance. This is done either by size,
colour, imagery, contrast, typography, whitespace, texture and style. One of the most important functions of
visual hierarchy is to establish a focal point; this shows visitors where the most important information is.
Content
An effective website has both great design and great content. Using compelling language great
content can attract and influence visitors by converting them into customers.
Grid Based Layout
help to structure your design and keep your content organised. The grid helps to align elements on
the page and keep it clean. The grid-based layout arranges content into a clean rigid grid structure with
columns, sections that line up and feel balanced and impose order and results in an aesthetically pleasing
website.
Load Time
Waiting for a website to load will lose visitors. Nearly half of web visitors expect a site to load in 2
seconds or less and they will potentially leave a site that isn’t loaded within 3 seconds. Optimising image
sizes will help load your site faster.
Mobile Friendly
More people are using their phones or other devices to browse the web. It is important to consider
building your website with a responsive layout where your website can adjust to different screens.
12. a) Explain the structure of html web page with examples. [UN] (13)
Structure of an HTML Document
An HTML document consists of specific tags that form the skeleton of the page. Here’s a look at a basic
HTML document structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Structure of HTML Document</title>
</head>
<body>
<!-- Main content of website -->
<h1>Welcome to HTML</h1>
<p>A computer science portal for VSB</p>
</body>
</html>
<!DOCTYPE HTML>: The <!DOCTYPE html> declaration is placed at the beginning of the document. It
tells the browser that the document follows HTML5 standards, ensuring consistent rendering across
browsers.
<html> Tag: The <html> tag wraps the entire document, serving as the root element of an HTML page. It
typically includes the lang attribute to specify the language of the content.
<head> Section: The <head> section contains metadata, scripts, styles, and other information not displayed
directly on the page but essential for functionality and SEO.
<body> Section: The <body> section contains all the visible content of the web page, including text, images,
videos, links, and more. This is where you’ll add the main elements to display on the page.
Tags and Elements for Structuring an HTML Document
HTML tags are structural components enclosed in angle brackets. They are typically opened and closed with
a forward slash (e.g., <h1></h1>). Some tags are self-closing, while others support attributes like width,
height, and controls for defining properties or storing metadata.
There are generally two types of tags in HTML
Paired Tags: These tags come in pairs i.e. they have both opening(< >) and closing(</ >) tags.
Empty Tags: These tags are self-closing and do not require a closing tag.”
Below is an example of a <b> tag in HTML, which tells the browser to bold the text inside it.
Understanding these key tags will allow you to organize content effectively and create more readable and
accessible webpages.
Headings (<h1> to <h6>): Headings are important for structuring the content within the <body> section.
They define the hierarchy of information, where <h1> is the highest-level heading.
Paragraphs (<p>): The <p> tag is used for creating paragraphs, which help to group text into readable
sections. This tag automatically adds some spacing between paragraphs to improve readability.
Images (<img>): The <img> tag is used to add images to a webpage. It requires the src attribute to specify
the image path and the alt attribute for accessibility.
Links (<a>):Links are created with the <a> tag. The href attribute defines the destination URL, and the text
within the <a> tag serves as the clickable link text.
Lists (<ul>, <ol>, <li>): Lists allow you to organize items in bullet points (<ul>) or numbered order (<ol>).
Each item within a list is wrapped in <li> tags.
Divisions (<div>): The <div> tag is a container used to group other elements together, often for layout. It
does not add any style or structure on its own but is useful for applying CSS styles to sections of content.
OR
b) Explain in detail about Cascading Style Sheet and its types with example. [AP] (13)
CSS stands for Cascading style sheets. It describes to the user how to display HTML elements on the
screen in a proper format. CSS is the language that is used to style HTML documents. In simple words,
cascading style sheets are a language used to simplify the process of making a webpage.
CSS is used to handle some parts of the webpage. With the help of CSS, we can control the colour of
text and style of fonts, and we can control the spacing between the paragraph and many more things. CSS is
easy to understand but provides strong control on the Html documents.CSS is combined with HTML.
Below are the types of CSS:
Inline CSS
Internal or Embedded CSS
External CSS
Inline CSS
Inline CSS involves applying styles directly to individual HTML elements using the style attribute.
This method allows for specific styling of elements within the HTML document, overriding any external or
internal styles.
HTML
<p style="color:#009900;
font-size:50px;
font-style:italic;
text-align:center;">
Inline CSS
</p>
Output
Inline CSS
Internal or Embedded CSS
Internal or Embedded CSS is defined within the HTML document’s <style> element. It applies styles
to specified HTML elements. The CSS rule set should be within the HTML file in the head section i.e. the
CSS is embedded within the <style> tag inside the head section of the HTML file.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
.main {
text-align: center;
}
.GFG {
color: #009900;
font-size: 50px;
font-weight: bold;
}
.geeks {
font-style: bold;
font-size: 20px;
}
</style>
</head>
<body>
<div class="main">
<div class="GFG">Internal CSS</div>
<div class="geeks">
Implementation of Internal CSS
</div>
</div>
</body>
</html>
CSS
body {
background-color: powderblue;
}
.main {
text-align: center;
}
.GFG {
color: #009900;
font-size: 50px;
font-weight: bold;
}
#geeks {
font-style: bold;
font-size: 20px;
}
Output
Internal CSS
Implementation of Internal CSS
External CSS
External CSS contains separate CSS files that contain only style properties with the help of tag
attributes (For example class, id, heading, … etc). CSS property is written in a separate file with a .css
extension and should be linked to the HTML document using a link tag. It means that, for each element,
style can be set only once and will be applied across web pages.
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main">
<div class="GFG">External CSS </div>
<div id="vsb">
This shows implementation of External CSS
</div>
</div>
</body>
</html>
CSS
body {
background-color: powderblue;
}
.main {
text-align: center;
}
.GFG {
color: #009900;
font-size: 50px;
font-weight: bold;
}
#vsb {
font-style: bold;
font-size: 20px;
}
Output
External CSS
This shows implementation of External CSS
Note: Inline CSS has the highest priority, so it overrides internal and external styles. Internal CSS comes
next, overriding external styles, while external CSS is applied only if no inline or internal styles are set.
13. a) Discuss the various built-in objects in Java Script with examples. [AP] (13)
In JavaScript, there are several built-in objects that are essential for performing various tasks, such as
handling data, interacting with the DOM (Document Object Model), managing asynchronous code, and
performing mathematical operations. These built-in objects are part of the JavaScript language specification
and are available for use out of the box.
Object
The Object is the fundamental building block for all non-primitive types in JavaScript. It is used to store
collections of data as key-value pairs (properties).
Example:
const person = {
name: 'John',
age: 30,
greet: function() {
console.log('Hello ' + this.name);
}
};
Array
The Array object is used to store multiple values in a single variable. It is an ordered collection, indexed by
numbers, and has methods for manipulating the elements.
Example:
const fruits = ['apple', 'banana', 'orange'];
Function
The Function object represents a callable function. Functions in JavaScript can be defined using function
declarations, function expressions, or arrow functions.
Example:
function greet(name) {
console.log('Hello, ' + name);
}
String
The String object is used to represent and manipulate sequences of characters. JavaScript strings are
immutable (cannot be changed directly), but you can perform various operations on them.
Example:
const message = "Hello, world!";
console.log(message.length); // Output: 13
console.log(message.toUpperCase()); // Output: HELLO, WORLD!
Number
The Number object represents numeric values, including integers, floating-point numbers, and special values
like NaN (Not-a-Number) and Infinity.
Example:
const num = 42;
console.log(num.toFixed(2)); // Output: 42.00 (rounds to two decimal places)
console.log(Number.isNaN('hello')); // Output: false
Boolean
The Boolean object is used to represent logical entities that can have one of two values: true or false.
Example:
const isActive = true;
console.log(isActive); // Output: true
Date
The Date object is used for working with dates and times. It can be used to create date instances, get the
current date and time, and manipulate them.
Example:
const currentDate = new Date();
console.log(currentDate); // Output: Current date and time, e.g., "2024-12-10T08:25:00.000Z"
console.log(currentDate.getFullYear()); // Output: 2024
Error
The Error object is used for creating error messages. It can also be extended to create custom error types.
Example:
try {
throw new Error("Something went wrong!");
} catch (e) {
console.log(e.message); // Output: Something went wrong!
}
Math
The Math object provides mathematical constants and functions like trigonometry, logarithms, and basic
arithmetic operations.
Example:
console.log(Math.PI); // Output: 3.141592653589793 (the value of Pi)
console.log(Math.sqrt(16)); // Output: 4 (square root of 16)
OR
b) Write a JavaScript code for validating new user registration form which includes the fields like
username, password, confirm password, gender, date of birth, contact number and mail id. [AP] (13)
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
.error { color: red; }
</style>
</head>
<body>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="Male"> Male
<input type="radio" id="female" name="gender" value="Female"> Female<br><br>
<div id="errorMessages"></div>
<script src="script.js"></script>
</body>
</html>
Javascript code
function validateForm() {
let valid = true;
let errorMessages = [];
// Validate Username
const username = document.getElementById("username").value;
if (username === "" || username.length < 3) {
errorMessages.push("Username must be at least 3 characters long.");
valid = false;
}
// Validate Password
const password = document.getElementById("password").value;
if (password === "" || password.length < 6) {
errorMessages.push("Password must be at least 6 characters long.");
valid = false;
}
// Validate Gender
const gender = document.querySelector('input[name="gender"]:checked');
if (!gender) {
errorMessages.push("Please select your gender.");
valid = false;
}
// Validate Email
const email = document.getElementById("email").value;
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!email.match(emailRegex)) {
errorMessages.push("Please enter a valid email address.");
valid = false;
}
14. a) Explain the various PHP operators with an example. [UN] (13)
PHP Operators
Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:
Arithmetic operators
Assignment operators
Comparison operators
Increment/Decrement operators
Logical operators
String operators
Array operators
Conditional assignment operators
The PHP arithmetic operators are used with numeric values to perform common arithmetical operations,
such as addition, subtraction, multiplication etc.
Operator Name Example Result
The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the
assignment expression on the right.
Assignment Same as... Description
x=y x=y The left operand gets set to the value of the expression on the
right
x += y x=x+y Addition
x -= y x=x-y Subtraction
x *= y x=x*y Multiplication
x /= y x=x/y Division
x %= y x=x%y Modulus
>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal
to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to
$y
OR
b) Discuss in detail about File Handling and File uploading in PHP with an example. [UN] (13)
File handling is the process of interacting with files on the server, such as reading file, writing to a
file, creating new files, or deleting existing ones. File handling is essential for applications that require the
storage and retrieval of data, such as logging systems, user-generated content, or file uploads.
Example
<?php
// Open the file in read mode
$file = fopen("gfg.txt", "r");
if ($file) {
echo "File opened successfully!";
fclose($file); // Close the file
} else {
echo "Failed to open the file.";
}
?>
<?php
$file = fopen("gfg.txt", "r");
$content = fread($file, filesize("gfg.txt"));
echo $content;
fclose($file);
?>
<?php
$file = fopen("gfg.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
echo $line . "<br>";
}
fclose($file);
}
?>
Writing to Files
You can write to files using the fwrite() function. It writes data to an open file in the specified mode.
<?php
// Open the file in write mode
$file = fopen("gfg.txt", 'w');
if ($file) {
$text = "Hello world\n";
fwrite($file, $text);
fclose($file);
}
?>
Deleting Files
Use the unlink() function to delete the file in PHP.
<?php
if (file_exists("gfg.txt")) {
unlink("gfg.txt");
echo "File deleted successfully!";
} else {
echo "File does not exist.";
}
?>
PHP allows you to upload single and multiple files through few lines of code only.
PHP file upload features allows you to upload binary and text files both. Moreover, you can have the full
control over the file to be uploaded through PHP authentication and file operation functions.
PHP $_FILES
The PHP global $_FILES contains all the information of file. By the help of $_FILES global, we can get file
name, file type, file size, temp file name and errors associated with file.
$_FILES['filename']['name']
$_FILES['filename']['type']
returns MIME type of the file.
$_FILES['filename']['size']
returns size of the file (in bytes).
$_FILES['filename']['tmp_name']
returns temporary file name of the file which was stored on the server.
$_FILES['filename']['error']
move_uploaded_file() function
The move_uploaded_file() function moves the uploaded file to a new location. The move_uploaded_file()
function checks internally if the file is uploaded thorough the POST request. It moves the file if it is
uploaded through the POST request.
Syntax:
bool move_uploaded_file ( string $filename , string $destination )
Example
HTML
<form action="uploader.php" method="post" enctype="multipart/form-data">
Select File:
<input type="file" name="fileToUpload"/>
<input type="submit" value="Upload Image" name="submit"/>
</form>
PHP
<?php
$target_path = "e:/";
$target_path = $target_path.basename( $_FILES['fileToUpload']['name']);
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_path)) {
echo "File uploaded successfully!";
} else{
echo "Sorry, file not uploaded, please try again!";
}
?>
15. a) What is Java Servlet? Explain the life cycle of Java Servlet with an example. [UN] (13)
Stages of the Servlet Life Cycle: The Servlet life cycle mainly goes through four stages,
Loading a Servlet.
Initializing the Servlet.
Request handling.
Destroying the Servlet.
Loading a Servlet: The first stage of the Servlet lifecycle involves loading and initializing the Servlet by the
Servlet container. The Web container or Servlet Container can load the Servlet at either of the following two
stages :
Initializing the context, on configuring the Servlet with a zero or positive integer value.
If the Servlet is not preceding stage, it may delay the loading process until the Web container determines that
this Servlet is needed to service a request.
Initializing a Servlet:
After the Servlet is instantiated successfully, the Servlet container initializes the instantiated Servlet
object. The container initializes the Servlet object by invoking the Servlet.init(ServletConfig) method which
accepts ServletConfig object reference as parameter.
The Servlet container invokes the Servlet.init(ServletConfig) method only once, immediately after
the Servlet.init(ServletConfig) object is instantiated successfully. This method is used to initialize the
resources, such as JDBC datasource.
Now, if the Servlet fails to initialize, then it informs the Servlet container by throwing the ServletException
or UnavailableException.
Handling request:
After initialization, the Servlet instance is ready to serve the client requests. The Servlet container
performs the following operations when the Servlet instance is located to service a request
It creates the ServletRequest and ServletResponse objects.
In this case, if this is a HTTP request, then the Web container creates HttpServletRequest and
HttpServletResponse objects which are subtypes of the ServletRequest and ServletResponse objects
respectively. After creating the request and response objects it invokes the Servlet.service(ServletRequest,
ServletResponse) method by passing the request and response objects.
The service() method while processing the request may throw the ServletException or UnavailableException
or IOException.
Destroying a Servlet:
When a Servlet container decides to destroy the Servlet, it performs the following operations,
It allows all the threads currently running in the service method of the Servlet instance to complete their jobs
and get released.
After currently running threads have completed their jobs, the Servlet container calls the destroy()
method on the Servlet instance.After the destroy() method is executed, the Servlet container releases all the
references of this Servlet instance so that it becomes eligible for garbage collection.
Example
Index.HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Servlet Example</title>
</head>
<body>
<h2>Welcome to the Java Servlet Example</h2>
<form action="greet" method="post">
Enter your name: <input type="text" name="name">
<input type="submit" value="Submit">
</form>
</body>
</html>
Greetservlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
web-app/
├── WEB-INF/
│ ├── classes/
│ │ └── GreetServlet.class
│ ├── lib/ (Any required libraries)
│ └── web.xml
├── index.html
The web.xml file is used to map a URL pattern to a specific servlet. Create a web.xml file inside the WEB-
INF directory to configure the servlet.
Methods in Cookies
clone(): Overrides the standard java.lang.Object.clone method to return a copy of this Cookie.
getComment(): Returns the comment describing the purpose of this cookie, or null if the cookie has
no comment.
getDomain(): Gets the domain name of this Cookie.
getMaxAge(): Gets the maximum age in seconds of this Cookie.
getName(): Returns the name of the cookie.
getPath(): Returns the path on the server to which the browser returns this cookie.
getSecure(): Returns true if the browser is sending cookies only over a secure protocol, or false if the
browser can send cookies using any protocol.
getValue(): Gets the current value of this Cookie.
getVersion(): Returns the version of the protocol this cookie complies with.
setValue(String newValue): Assigns a new value to this Cookie.
setVersion(int v): Sets the version of the cookie protocol that this Cookie complies with.
Example
The name of the Institute is passed to Servlet 2 from Servlet 1 using Cookies.
HTML
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<!-- css-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-
awesome.min.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="servlet1" method="POST">
<div class="container-fluid ">
<div class="jumbotron">
<div class="container col-sm-4">
<h2>Enter your institute's name</h2>
<input type="text" name="name" style="font-size:30px;">
<br>
<br>
<!-- button to redirect to servlet1 -->
<button type="submit" style="font-size:20px;" class="center">
Go !
</button>
<br><br>
</div>
</div>
</div>
</form>
</body>
</html>
Java Servlet 1
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
protected void
processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Servlet1</title>");
out.println("</head>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
}
}
}
Java Servlet 2
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
out.println("</body>");
out.println("</html>");
}}}
PART-C (1 x 15 = 15 Marks)
16. a) Create a form for student information with needed controls. Write a java script code to find
total, average, result and grade. [AN] (15)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Information Form</title>
<script src="student.js"></script>
</head>
<body>
<h2>Student Information Form</h2>
<form id="studentForm">
<label for="name">Student Name:</label>
<input type="text" id="name" name="name" required><br><br>
<h3>Result</h3>
<div id="result">
<p id="total">Total: </p>
<p id="average">Average: </p>
<p id="grade">Grade: </p>
<p id="status">Result: </p>
</div>
</body>
</html>
// Validate input to ensure all values are numbers and within range
if (isNaN(subject1) || isNaN(subject2) || isNaN(subject3) || isNaN(subject4) || isNaN(subject5)) {
alert("Please enter valid marks for all subjects.");
return;
}
// Calculate average
var average = total / 5;
b) Develop a simple database connectivity program for Hospital management system. [AN] (15)
A complete, fully functional Hospital Management System involves a more extensive and complex
codebase. However, I can provide a simplified version focusing on patients, doctors, and appointments using
PHP, HTML, and MySQL.
Database Setup:
CREATE DATABASE IF NOT EXISTS hospital_management_system;
USE hospital_management_system;
}}
function displayDoctors() {
global $conn;
function displayAppointments() {
global $conn;
$conn->close();
?>