WT_LabFile
WT_LabFile
(BCS-552)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Aim : Write HTML program for designing your ins tute website. Display
departmental informa on of your ins tute on the website.
ti
ti
ti
OUTPUT :
EXPERIMENT 02
Index.htm
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Entry Form for Student Details</title>
<link rel="StyleSheet" href="Style.css">
</head>
<body>
<div class="container">
<h2>Student Entry Form</h2>
<form action="#" method="post">
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="course">Course:</label>
<select id="course" name="course" required>
<option value="">Select Course</option>
<option value="computer-science">Computer Science</option>
<option value="mechanical-engineering">Mechanical
Engineering</option>
<option value="electrical-engineering">Electrical
Engineering</option>
<option value="civil-engineering">Civil Engineering</option>
</select>
ti
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob" required>
</body>
</html>
Style.css
body {
font-family: Arial, sans-
serif; background-color:
#f4f4f4; margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: white;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h2 {
text-align: center;
color: #007BFF;
}
label {
display: block;
margin: 10px 0 5px;
}
input[type="text"],
input[type="email"],
input[type="tel"],
select {
width: 100%;
padding: 10px;
margin: 5px 0
15px;
border: 1px solid
#ccc; border-radius:
5px;
}
input[type="submit"]
{ background-color:
#007BFF; color: white;
border: none;
padding: 10px;
border-radius:
5px; cursor:
pointer; font-
size: 16px;
OUTPUT:
EXPERIMENT 03
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Blog</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>My Blog</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#blog">Blog</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="about">
<h2>About Me</h2>
<p>Welcome to my blog! I share my thoughts on technology,
lifestyle, and everything in between.</p>
</section>
<section id="blog">
<h3>Post Title 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Integer nec odio. Praesent libero. Sed cursus ante dapibus diam.</p>
</div>
<div class="post">
<h3>Post Title 2</h3>
<p>Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis
sagittis ipsum. Praesent mauris.</p>
</div>
<div class="post">
<h3>Post Title 3</h3>
<p>Fusce nec tellus sed augue semper porta. Mauris massa.
Vestibulum lacinia arcu eget nulla.</p>
</div>
</section>
</main>
<footer>
<p>© 2024 My Blog. All Rights Reserved.</p>
</footer>
</body>
Style.css
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-
serif; line-height: 1.6;
background-color: #f4f4f4;
}
background:#007BFF;
color: whit;
padding: 20px 0;
text-align: center;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
display: inline;
margin: 0 15px;
}
nav ul li a {
color: white;
text-decoration: none;
}
main {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background: white;
border-radius:
8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #007BFF;
margin-bottom:
10px;
}
.post {margin-bottom: 20px; padding: 15px;border: 1px solid #ccc;
border-radius:5px;}
footer {
text-align: center;
padding: 10px;
background: #333;
color: white;
}
main {
padding: 10px;
OUTPUT:
EXPERIMENT 04
Aim : Write programs using HTML and Java Script for valida on
of input data.
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Input Validation Form</title>
<link rel="StyleSheet" href="Style.css">
</head>
<body>
<script src="Script.js"></script>
<div class="container">
<h2>Registration Form</h2>
<form id="registrationForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<div class="error" id="usernameError">Please enter a username.</div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<div class="error" id="emailError">Please enter a valid email.</div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<div class="error" id="passwordError">Please enter a password.</div>
</div>
</body>
</html>
ti
Style.css
body {
font-family: Arial, sans-
serif; background-color:
#f4f4f4; margin: 0;
padding: 20px;
}
.container {
max-width: 400px;
margin: auto;
padding: 20px;
background:
white; border-
radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: #007BFF;
}
label {
display: block;
margin: 10px 0
5px;
}
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"] {
width: 100%;
padding: 10px;
margin: 5px 0
15px;
font-size: 0.9em;
display: none;
}
input[type="submit"]
{ background-color:
#007BFF; color: white;
border: none;
padding: 10px;
border-radius:
5px; cursor:
pointer; font-
size: 16px;
width: 100%;
}
input[type="submit"]:hover
Javascript:-
document.getElementById('registrationForm').addEventListener('submit',
function(event) {
let valid = true;
// Validate Username
const username =
document.getElementById('username').value; if (username
=== '') {
document.getElementById('usernameError').style.display =
'block'; valid = false;
}
// Validate Email
const email =
document.getElementById('email').value; const
valid = false;
}
// Validate Password
const password =
document.getElementById('password').value; if
(password === '') {
document.getElementById('passwordError').style.display =
'block'; valid = false;
}
if (!valid) {
OUTPUT:
EXPERIMENT 05
Data.xml
<year>2022</year>
<genre>Education</genre>
</book>
</library>
fi
ti
Library.dtd
<!ELEMENT library (book+)>
<!ELEMENT book (title, author, year, genre)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT genre (#PCDATA)>
Style.xsl
const rl =
readline.createInterface({ input:
process.stdin,
output: process.stdout
});
const rl =
readline.createInterface({ input:
process.stdin,
output: process.stdout
});
function factorial(n)
{ if (n === 0
|| n === 1) {
return 1;
} else {
}
function generatePassword(length) {
const charset =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$
%^&*()_-=';
let password = '';
for (let i = 0; i < length; i++) {
password += charset[crypto.randomInt(0,
charset.length)];
}
return password;
}
const rl =
readline.createInterface({ input:
process.stdin,
output: process.stdout
});
Output:
fi
Experiment - 08
Prerequisites:
1. Install MongoDB Driver: npm install mongodb
2. Have a MongoDB database with a users collection.
Code:
aggregate-users.js:
const { MongoClient } = require('mongodb');
// MongoDB URI and Database/
Collec on Names const uri =
"mongodb+srv://
akadityakumar421:*****@cluster0.6sivg.mongodb.ne t/";
const dbName =
"userDB"; const
collec onName =
"users";
async func on
aggregateUserData() { const
client = new MongoClient(uri);
try {
// Connect to the MongoDB server
await client.connect();
console.log("Connected to MongoDB");
ti
ti
ti
ti
ff
ti
ti
fi
fi
ti
const db = client.db(dbName);
const collec on = db.collection(collectionName);
// Aggrega on
Pipeline const
pipeline = [
{
$group: {
_id: "$city",
averageAge: { $avg: "$age"
}, userCount: { $sum: 1 }
}
},
{ $sort: { averageAge: -1 } }
];
console.log("Aggrega on
Result:"); console.log(result);
}
catch (err) {
console.error("Error performing aggrega on:", err);
}
nally {
// Close the
connec on
await
client.close();
console.log("MongoDB connection closed");
}
fi
ti
ti
ti
ti
ti
ti
}
Output:
ti
ti
Experiment - 09
Aim: Assume four users user1, user2, user3 and user4 having
the passwords pwd1, pwd2, pwd3 and pwd4 respec vely.
Write a servlet for doing the following:
1. Create a Cookie and add these four user id’s and passwords
to this Cookie.
2. Read the user id and passwords entered in the Login form
and authen cate with the values available in the cookies.
Code:
LoginServlet.java:
import
java.io.*;
import
javax.servlet.
*;
import javax.servlet.http.*;
// Set the max age for cookies (op onal, 1 day here)
user1.setMaxAge(24 * 60 * 60);
user2.setMaxAge(24 * 60 * 60);
user3.setMaxAge(24 * 60 * 60);
user4.setMaxAge(24 * 60 * 60);
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(userId)
&& cookie.getValue().equals(password)) {
isAuthen cate
d = true; break;
}
}
}
Code:
1. Create the Database Table:
CREATE DATABASE
user_database; USE
user_database;
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY
KEY, name VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT
NULL, email_id VARCHAR(100)
UNIQUE NOT NULL,
phone_number VARCHAR(15) NOT NULL );
2. register.jsp:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
ini al- scale=1.0">
< tle>User Registration</title>
</head>
<body>
fi
ti
ti
tt
ti
<h2>User Registration</h2>
<form ac on="RegisterServlet" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"
required>
<br><br>
<label for="email">Email ID:</label>
<input type="email" id="email" name="email" required>
<br><br>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone" required>
<br><br>
<bu on type="submit">Register</button>
</form>
</body>
</html>
3. RegisterServlet.java:
import
java.io.*;
import
java.sql.*;
import
javax.servlet.
*;
import javax.servlet.http.*;
@Override
protected void doPost(H pServletRequest request,
H pServletResponse response) throws ServletExcep on,
IOExcep on {
response.setContentType("text/html");
if (rows > 0) {
out.println("<h2>Registration Successful!</h2>");
} else {
out.println("<h2>Registra on Failed. Try again!</h2>");
}
// Display all users
out.println("<h2>Registered
Users:</h2>");
String selectQuery = "SELECT name, email_id,
phone_number FROM users";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(selectQuery);
out.println("<table border='1'><tr><th>Name</
th><th>Email ID</th><th>Phone Number</th></tr>");
while (resultSet.next()) {
out.println("<tr><td>" + resultSet.getString("name") +
"</td><td>" +
resultSet.getString("email_id") + "</td><td>" +
resultSet.getString("phone_number") + "</td></tr>");
}
out.println("</table>");
} catch (SQLExcep on
e)
{ e.printStackTrace()
ti
ti
;
out.println("<h2>Error: " + e.getMessage() + "</h2>");
}
}
}
Output:
Experiment - 11
Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Register Here</h1>
<label for="username">Username:</label>
<label for="email">Email:</label>
</form>
<h1>Login Here</h1>
<label for="loginUsername">Username:</label>
<label for="loginPassword">Password:</label>
</body>
</html>
<%
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connec on conn =
DriverManager.getConnec on("jdbc:mysql://localhost:3306/
yourdatabase", "root", "password");
PreparedStatement stmt =
conn.prepareStatement(query);
ti
ti
stmt.setString(1, username);
stmt.setString(2, password);
stmt.setString(3, email);
stmt.executeUpdate();
out.println("<h1>Registra on Successful</h1>");
} catch (Excep on e) {
%>
<%
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connec on conn =
DriverManager.getConnec on("jdbc:mysql://localhost:3306/
ti
ti
ti
ti
yourdatabase", "root", "password");
PreparedStatement stmt =
conn.prepareStatement(query);
stmt.setString(1, username);
stmt.setString(2, password);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
out.println("<h1>Login Successful</h1>");
} else {
} catch (Excep on e) {
%>
ti
ti
Output:
Experiment - 12
Code:
package com.example;
import java.io.PrintWriter;
@WebServlet("/ShoppingCart")
@Override
response.setContentType("text/html");
if (cart == null) {
cart.add(item);
if (cart.isEmpty()) {
tt
tt
ti
tt
tt
ti
ti
ti
out.println("<p>Your cart is empty.</p>");
} else {
out.println("<ul>");
out.println("</ul>");
out.println("<form ac on='ShoppingCart'
method='GET'>");
out.println("</form>");
out.println("<h2>Session Details</h2>");
out.println("</body></html>");
@Override
ti
protected void doPost(H pServletRequest request,
H pServletResponse response) throws ServletExcep on,
IOExcep on {
doGet(request, response);
Output:
tt
ti
tt
ti