WT Lab Vikas
WT Lab Vikas
Submitted By,
Student Name: Vikas Singh
Roll no.: 2202220100191
Faculty Name: Ms.Tanmayee Tilekar
1|Page
Department of Computer Science & Engineering
2|Page
user4 having the passwords pwd1, pwd2,
pwd3 and pwd4 respectively. Write a servlet
for doing the following:
1. Write HTML program for designing your institute website. Display departmental
information of your institute on the website.
3|Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Institute Website</title>
</head>
<body>
<header>
</header>
<nav>
<ul>
href="#department3">Department 3</a></li>
</ul>
</nav>
<main>
<section id="department1">
<h2>Department 1</h2>
4|Page
</section>
<section id="department2">
<h2>Department 2</h2>
</section>
<section id="department3">
<h2>Department 3</h2>
</section>
</main>
<footer>
</body>
</html>
Output:
5|Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Entry Form</title>
</head>
<body>
<h1>Entry Form</h1>
<form action="submit_form.php" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
Output:
6|Page
3. Develop a responsive website using CSS and HTML. Website may be for
tutorial/blogs/commercial website.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Responsive Website</title>
</head>
<body>
<header>
<h1>My Blog</h1>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<main>
<article>
<h2>Blog Post Title</h2>
7|Page
</article>
</main>
<footer>
</footer>
</body>
</html>
{ padding: 20px;
margin: 10px;
navul { list-style-type:
none;
navul li { display:
inline; margin-right:
10px;
block; margin:
5px 0;
Output:
9|Page
4. Write programs using HTML and Java Script for validation of input data.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Input Validation</title>
10 | P a g e
<script> functionvalidateForm() { const name = document.getElementById("name").value;
return true;
</script>
</head>
<body>
<label for="name">Name:</label>
</form>
</body>
</html> Output:
11 | P a g e
5. Write a program in XML for creation of DTD, which specifies set of rules. Create a style
sheet in CSS/ XSL & display the document in internet explorer.
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
CSS:
note {
12 | P a g e
font-family: Arial, sans-serif;
}
Output:
6. Create a Java Bean for Employee information (Employer ID, Name, Salary, Designation
and Department).
14 | P a g e
public void setDepartment(String department) { this.department =
department;
}
}
Output:
7. Build a command-line utility using Node.js that performs a specific task, such as
converting text to uppercase, calculating the factorial of a number, or generating random
passwords.
constreadline = require('readline');
constrl = readline.createInterface({ input:
process.stdin,
output: process.stdout
});
15 | P a g e
16 | P a g e
8. Develop a script that uses MongoDB's aggregation framework to perform operations like
grouping, filtering, and sorting. For instance, aggregate user data to find the average age
of users in different cities.
db.users.aggregate([
$group: {
_id: "$city",
},
$sort: { averageAge: 1 }
}
]);
Output:
17 | P a g e
15 | P a g e
9. Assume four users user1, user2, user3 and user4 having the passwords pwd1, pwd2, pwd3
and pwd4 respectively. 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 authenticate with the
values available in the cookies.
Output:
19 | P a g e
18 | P a g e
10. Create a table which should contain at least the following fields: name, password, email-
id, phone number Write Servlet/JSP to connect to that database and extract data from the
tables and display them. Insert the details of the users who register with the web site,
whenever a new user clicks the submit button in the registration
page.
Login Form:
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8"
language="java" %>
<html>
<head>
<title>User Login</title>
</head>
<body>
<h2>User Login</h2>
<form action="login.jsp" method="post">
Email: <input type="email" name="email" required><br>
Password: <input type="password" name="password" required><br>
<input type="submit" value="Login">
</form>
</body>
</html>
<% if (request.getMethod().equalsIgnoreCase("POST")) {
String email = request.getParameter("email");
String password = request.getParameter("password");
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user",
"password");
PreparedStatementps = con.prepareStatement("SELECT * FROM users WHERE
email=? AND password=?"); ps.setString(1, email); ps.setString(2, password);
ResultSetrs = ps.executeQuery();
if (rs.next()) {
out.println("Login successful! Welcome, " + rs.getString("name"));
} else {
out.println("Invalid email or password.");
}
21 | P a g e
con.close();
} catch (Exception e) { e.printStackTrace();
out.println("Login failed: " + e.getMessage());
}
}
%>
Register:
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8"
language="java" %>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h2>User Registration</h2>
<form action="register.jsp" method="post">
Name: <input type="text" name="name" required><br>
Email: <input type="email" name="email" required><br>
Password: <input type="password" name="password" required><br>
<input type="submit" value="Register">
</form>
</body>
</html>
<%
if (request.getMethod().equalsIgnoreCase("POST")) { String
name = request.getParameter("name");
String email = request.getParameter("email");
String password = request.getParameter("password");
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user",
"password");
PreparedStatementps = con.prepareStatement("INSERT INTO users (name, email,
password) VALUES (?, ?, ?)"); ps.setString(1, name); ps.setString(2, email);
ps.setString(3, password); ps.executeUpdate(); con.close();
out.println("Registration successful!");
} catch (Exception e)
{ e.printStackTrace();
22 | P a g e
out.println("Registration failed: " + e.getMessage());
}
}
%>
Output:
12. Design and implement a simple shopping cart example with session tracking API.
23 | P a g e
Cart:
<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Shopping Cart</title>
</head>
<body>
<h2>Shopping Cart</h2>
<%
List<String> cart = (List<String>) session.getAttribute("cart");
if (cart == null) {
cart = new ArrayList<>();
}
if (cart.isEmpty()) {
out.println("Your cart is empty.");
} else {
out.println("Items in your cart:<br>"); for
(String cartItem : cart) {
out.println(cartItem + "<br>");
}
}
%>
<form action="cart.jsp" method="get">
<label for="item">Add Item:</label>
<input type="text" name="item" required>
<input type="submit" value="Add to Cart">
</form>
<a href="checkout.jsp">Checkout</a>
</body>
</html>
Checkout :
24 | P a g e
<%@ page contentType="text/html;charset=UTF- 8" language="java" %>
<html>
<head>
<title>Checkout</title>
</head>
<body>
<h2>Checkout</h2>
<%
cart.isEmpty()) { out.println("Your cart is empty. Please add items to your cart before
checking out.");
} else
{ out.println("Items in
{ out.println(cartItem +
"<br>");
%>
</body>
</html>
25 | P a g e
Output:
25 | P a g e