0% found this document useful (0 votes)
13 views15 pages

IWP FAT Solution E1 SLOT

Uploaded by

shrikijaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

IWP FAT Solution E1 SLOT

Uploaded by

shrikijaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Below is a detailed response to each question with step-by-step explanations, code examples,

and descriptions:
---

Question 1. a) Web Protocols, Web Architecture, and HTTP Request-Response Cycle

Web Protocols vs. Web Architecture

1. Web Protocols:

Definition: Rules for data communication over the web.

Examples: HTTP, HTTPS, FTP, TCP/IP.

Purpose: Ensure data integrity, secure transmission, and interoperability.

2. Web Architecture:

Definition: Design framework for web application deployment.

Examples: Client-server model, three-tier architecture, RESTful architecture.

Purpose: Organize components (front-end, back-end, database) for scalability and efficiency.

HTTP Request-Response Cycle

1. Steps:

Client Request: User requests a resource (e.g., a homepage).

DNS Lookup: Resolves the domain name to an IP address.

Connection Established: TCP connection is established.

Request Sent: HTTP request is sent to the server.

Server Processing: Server processes the request and retrieves data.

Response Sent: Server sends an HTTP response with the requested resource.

Rendering: Browser renders the resource.


2. Example HTTP Request and Response

Request:

GET /index.html HTTP/1.1


Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html

Response:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234

---

Question 1. b) Web Security Threats

1. SQL Injection:

Nature: Malicious SQL queries manipulate the database.

Impact: Data leaks, unauthorized access, or database damage.

2. Cross-Site Scripting (XSS):

Nature: Injected scripts run in users' browsers.

Impact: Session hijacking, phishing, or malware delivery.


3. Cross-Site Request Forgery (CSRF):

Nature: Unauthorized actions on authenticated sessions.

Impact: Account compromise or unwanted transactions.

4. Denial of Service (DoS):

Nature: Overloading the server with requests.

Impact: Downtime and loss of user trust.

---

Question 2. Learning Module for Web 3.0

HTML Table for Learning Outcomes

<table border="1">
<tr>
<th>Topic</th>
<th>Learning Outcome</th>
<th>Estimated Time</th>
</tr>
<tr>
<td>Blockchain</td>
<td>Understand decentralized systems</td>
<td>3 hours</td>
</tr>
<tr>
<td>AI Integration</td>
<td>Learn AI-based web solutions</td>
<td>4 hours</td>
</tr>
<tr>
<td>Semantic Web</td>
<td>Explore Web 3.0 features</td>
<td>2 hours</td>
</tr>
</table>

Image, Caption, and Embedded Video

<figure>
<img src="module.jpg" alt="Web 3.0 Concept Image">
<figcaption>Web 3.0 Learning Module</figcaption>
</figure>

<video controls>
<source src="web3-intro.mp4" type="video/mp4">
<track src="web3-caption.vtt" kind="captions" srclang="en" label="English">
</video>
<figcaption>Introduction to Web 3.0</figcaption>

List of Reading Resources

<ul>
<li><a href="https://example.com/web3-basics" target="_blank">Web 3.0 Basics</a></li>
<li><a href="https://example.com/blockchain-intro" target="_blank">Introduction to
Blockchain</a></li>
<li><a href="https://example.com/ai-web" target="_blank">AI Integration in Web 3.0</a></li>
</ul>

---

Question 3. Donation Platform and PHP Superglobals

PHP Superglobals and Their Role

1. $_POST:

Collects form data securely.

Example: Process donor name, email, and donation amount.

2. $_SESSION:

Maintains user sessions (e.g., login state).


Example: Track donor history.

3. $_GET:

Handles query strings in URLs.

Example: View specific donation details.

4. $_SERVER:

Provides server information.

Example: Log server activity.

Illustration: Processing Donation Form

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = htmlspecialchars($_POST['name']);
$amount = (float)$_POST['amount'];
echo "Thank you, $name, for donating $amount.";
}

---

Question 4. Student Admission System

Database and Table

CREATE DATABASE school;


USE school;

CREATE TABLE students_data (


Sid INT PRIMARY KEY NOT NULL,
Sname VARCHAR(50) UNIQUE NOT NULL,
Addrl VARCHAR(100) NOT NULL,
Sdob DATE NOT NULL,
Phone_number VARCHAR(15) NOT NULL,
Email VARCHAR(50) NOT NULL,
Total_Mark INT NOT NULL
);

Insert and Display Data

$conn = new mysqli("localhost", "root", "", "school");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$sql = "INSERT INTO students_data VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("isssssi", $id, $name, $addr, $dob, $phone, $email, $marks);
$stmt->execute();
}

Display Top 2 Students

$sql = "SELECT * FROM students_data ORDER BY Total_Mark DESC LIMIT 2";


$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<tr><td>{$row['Sname']}</td><td>{$row['Total_Mark']}</td></tr>";
}

---

Question 5. AJAX-Based Search Page

<input type="text" id="keyword">


<button onclick="search()">Search</button>
<div id="results"></div>

<script>
function search() {
const keyword = document.getElementById('keyword').value;
fetch(`https://api.example.com/search?keyword=${keyword}`)
.then(res => res.json())
.then(data => {
let output = "<ul>";
data.forEach(item => output += `<li>${item.title}</li>`);
output += "</ul>";
document.getElementById('results').innerHTML = output;
});
}
</script>

---

Here are detailed solutions to questions 6, 7, 8, and 9:

---

Question 6

a) Create an XML document for a bookstore with 3 records

<bookstore>
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<price>200.50</price>
<publish_year>1925</publish_year>
</book>
<book>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<price>150.75</price>
<publish_year>1960</publish_year>
</book>
<book>
<title>1984</title>
<author>George Orwell</author>
<price>180.00</price>
<publish_year>1949</publish_year>
</book>
</bookstore>

b) Write a DTD to validate this XML

<!DOCTYPE bookstore [
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, price, publish_year)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT publish_year (#PCDATA)>
]>

c) Develop an XSLT stylesheet to transform the XML into an HTML table

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


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>Title</th>
<th>Author</th>
<th>Price</th>
<th>Publication Year</th>
</tr>
<xsl:for-each select="bookstore/book[price > 150]">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="publish_year"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

---

Question 7

Develop an application using Node.js and MongoDB to perform operations on an "Employee"


collection.

Node.js Script

const { MongoClient } = require("mongodb");

const url = "mongodb://localhost:27017";


const dbName = "companyDB";

(async function () {
const client = new MongoClient(url);
try {
await client.connect();
console.log("Connected to the database");

const db = client.db(dbName);
const collection = db.collection("Employee");

// Insert multiple records


await collection.insertMany([
{ Emp_ID: 1, Emp_name: "Alice", age: 25, DOB: "1998-01-10", School: "ABC",
Date_of_Join: "2020-06-15" },
{ Emp_ID: 2, Emp_name: "Bob", age: 45, DOB: "1978-04-20", School: "XYZ",
Date_of_Join: "2015-03-10" },
{ Emp_ID: 3, Emp_name: "John", age: 28, DOB: "1995-08-30", School: "LMN",
Date_of_Join: "2021-01-01" },
]);

// Sort all documents


console.log(await collection.find().sort({ Emp_name: 1 }).toArray());

// Update John's age


await collection.updateOne({ Emp_name: "John" }, { $set: { age: 30 } });

// Limit query result to 4 documents


console.log(await collection.find().limit(4).toArray());

// Retrieve documents where age > 40


console.log(await collection.find({ age: { $gt: 40 } }).toArray());

} catch (err) {
console.error(err);
} finally {
client.close();
}
})();

---

Question 8
To-Do List Application (HTML and CSS)

HTML

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>To-Do List</h1>
<div id="task-container">
<ul id="task-list">
<!-- Tasks will appear here -->
</ul>
<input type="text" id="task-input" placeholder="Add a new task...">
<button id="add-task-btn">Add Task</button>
</div>
</body>
</html>

CSS

body {
font-family: Arial, sans-serif;
text-align: center;
margin: 20px;
}

#task-container {
width: 50%;
margin: auto;
}

#task-list li {
margin: 5px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

.completed {
text-decoration: line-through;
color: gray;
}

#add-task-btn {
padding: 10px 20px;
background-color: blue;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

#add-task-btn:hover {
background-color: darkblue;
}

---

Question 9

a) JavaScript Code to Count Words, Characters, and Lines

const paragraph = "This is a sample paragraph.\nIt has multiple lines.\nAnd it ends here.";

function analyzeText(text) {
const wordCount = text.split(/\s+/).filter(word => word).length;
const charCount = text.length;
const lineCount = text.split("\n").length;

return { wordCount, charCount, lineCount };


}

console.log(analyzeText(paragraph));

b) Interactive Quiz Application

HTML

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<form id="quiz-form">
<p>1. What is 2 + 2?</p>
<input type="radio" name="q1" value="3"> 3<br>
<input type="radio" name="q1" value="4"> 4<br>
<input type="radio" name="q1" value="5"> 5<br>

<p>2. What is the capital of France?</p>


<input type="radio" name="q2" value="Berlin"> Berlin<br>
<input type="radio" name="q2" value="Paris"> Paris<br>
<input type="radio" name="q2" value="Madrid"> Madrid<br>

<button type="button" id="submit-btn">Submit</button>


</form>

<p id="score"></p>
</body>
<script>
$("#submit-btn").click(function () {
let score = 0;

if ($("input[name='q1']:checked").val() === "4") score++;


if ($("input[name='q2']:checked").val() === "Paris") score++;

$("#score").text("Your score is: " + score);


});
</script>
</html>

You might also like