WebTech Lab
WebTech Lab
Practical File
Web Technology Lab (BCS 552)
Session 2024-25
SUBMITTED BY SUBMITTED TO
S. NO EXPERIMENT TITLE DATE SIGNATURE
1. Write HTML program
for designing your
institute
website. Display departmental
information of your institute
on
the website
2. Write HTML program to
design an entry form for
student
details/employee
information/faculty
details.
3. Write programs using HTML
and Java Script for validation
of input data
4. Develop a responsive website
using CSS and HTML.
Websitemay be for
tutorial/blogs/commercial
website.
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.
6. Create a Java Bean for
Employee information (EmpID,
Name, Salary, Designation
and Department)
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
8 Write a JSP which insert the
details of the 3 or 4 users who
register with the web site by
using registration form.
Authenticate the user when he
submits the login form using
the user name and password
from the database
9 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.
10 Design and implement a
simple shopping cart example
with
session tracking API.
PROGRAM No.: -1
1.1 OBJECTIVE : Write HTML program for designing your institute website. Display
departmental information of your institute on the website
1.2 Theory :
Introduction:
HTML stands for Hyper Text Markup Language. HTML is the computer language that is used to
create documents for display on the web stary editors exist to create Web Pages - Word, Front
Page, and Draam Weaver are just a few Nevertheless, each of these software programs (editors)
performs the exact same task they all generate HTML language
The HTML language consists of a series of HTML tags Leaming HTML involves finding out what
togs are used to mark the parts of a document and how these tags are med in creating an HTML
document.
Tags are instructions that tell your browser what to show on a Web page. They break up your
document into basic sections. All tags start with a < (left bracket) and end with a > (right bracket)
Basic HTML Tags
<HTML><HTML>
This tag tells your browser that the file contains HTML-coded information. All html tags must be
placed between the open <HTML> tag and the closed tag <HTML> The file extension html also
indicates the document is an HTML document All html documents MUST be saved with the html
file extension.
<HEAD> </HEAD>
The head tag identifies the first part of your HTML-coded document. The title tag (explained
below) must be places between the open <HEAD> tag and the closed </HEAD> tag
<BODY></BODY>
The largest part of your HTML document is the body, which contains the content of your document
(displayed within the text area of your browser window) All HTML tags that pertain to the body
of your HTML document must be places between the open <BODY> tag and the closed </BODY>
tag. The tag has attributes which you can use to set the colors of your background, text, links, and
also to include your own background image. They are as follows.
1. BGCOLOR="white" Sets the background color (other color names red, black, blue etc.)
2. TEXT-"black" Sets the body text color
3. LINK "blue" Sets the unvisited hypertext links
4. VLINK="purple" Sets the visited hypertext links
5.
ALINK="red" Sets the active hypertext links (the color of the hypertext link when you have your
mouse button depressed)
1.3 Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AKTU Institute Website</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
color: #333;
}
header {
background-color: #004080;
color: white;
padding: 20px;
text-align: center;
}
nav {
background-color: #0066cc;
padding: 10px;
text-align: center;
}
nav a {
color: white;
margin: 0 15px;
text-decoration: none;
font-weight: bold;
}
nav a:hover {
text-decoration: underline;
}
section {
padding: 20px;
}
.department {
border: 1px solid #ddd;
padding: 15px;
margin: 15px 0;
background-color: white;
border-radius: 8px;
}
.department h3 {
color: #004080;
}
footer {
background-color: #004080;
color: white;
text-align: center;
padding: 10px 0;
position: fixed;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<header>
<h1>Welcome to AKTU Institute</h1>
<p>Your Gateway to Excellence in Education</p>
</header>
<nav>
<a href="#about">About Us</a>
<a href="#departments">Departments</a>
<a href="#contact">Contact</a>
</nav>
<section id="about">
<h2>About AKTU Institute</h2>
<p>AKTU Institute is a premier educational institution dedicated to providing quality
education and fostering innovation. We offer a wide range of programs across various disciplines
to shape future leaders and innovators.</p>
</section>
<section id="departments">
<h2>Departments</h2>
<div class="department">
<h3>Computer Science and Engineering</h3>
<p>Our CSE department focuses on cutting-edge technologies like AI, ML, and Data
Science. We aim to develop the next generation of tech leaders.</p>
</div>
<div class="department">
<h3>Electronics and Communication Engineering</h3>
<p>The ECE department emphasizes embedded systems, IoT, and wireless
communication, ensuring students are ready for industry challenges.</p>
</div>
<div class="department">
<h3>Mechanical Engineering</h3>
<p>Offering hands-on experience in CAD/CAM, robotics, and thermodynamics, our ME
department nurtures innovative mechanical engineers.</p>
</div>
<div class="department">
<h3>Civil Engineering</h3>
<p>With expertise in structural design, water resources, and sustainable construction, our
CE department builds a better future.</p>
</div>
<div class="department">
<h3>Management Studies</h3>
<p>Our management programs blend theoretical knowledge with practical insights to
prepare students for leadership roles.</p>
</div>
</section>
<section id="contact">
<h2>Contact Us</h2>
<p>Address: AKTU Institute, Knowledge Park, Lucknow, UP</p>
<p>Email: [email protected]</p>
<p>Phone: +91-123-456-7890</p>
</section>
<footer>
<p>© 2024 AKTU Institute. All Rights Reserved.</p>
</footer>
</body>
</html>
1.4 Output:
PROGRAM No -2
2.1 OBJECTIVE : Write HTML program to design an entry form for student
details/employee information/faculty details
2.2 Theory :
Introduction:
HTML Forms
HTML Forms are required to collect different kinds of user inputs, such as contact details like
name, email address, phone numbers, or detach like credit card information, etc.
Forms contain special elements called controls like input box, checkboxes, radio-buttons, submit
buttons, etc. Users generally complete a form by modifying as controls eg. entering text selecting
items, etc. and submitting this form to a web server for processing
The <form> tag is used to create an HTML form. Here's a simple example of a login form
Input Element
This is the most commonly used element within HTML forms. It allows you to specify various
types of user input fields, depending on the type attribute. An input clement can be of type test
field, checkbox, password field, radio button, submit button, react button, etc. and several age input
types introduced in HTML5
Text Fields Text fields are one line areas that allow the user to input text Single-line text input
controls are created using an input element, whose type attribute has a value of text. Here's an
example of a single-line text input used to take full Name
Password Field
Password fields are similar to text fields. The only difference is, characters in a password field are
masked i.e. shown as asterisks or dots. This is to prevent others from reading the password on the
screen. This is also a single-line text input controls created using an input element where type
attribute has a value of password
Here's an example of a single-line password input used to take user password
Radio Buttons
Radio buttons are used to let the user select exactly one option from a pre-defined set of options It
is created using an <input> element whose type attribute has a value of radio
Checkboxes
Checkboxes allows the user to select one or more option from a pre-defined set of optans . It is
created using an <input> element whose type attribute has a value of checkbox
2.3 Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Entry Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
max-width: 400px;
margin: 0 auto;
}
label {
display: block;
margin: 10px 0 5px;
}
input, select, button {
width: 100%;
padding: 8px;
margin-bottom: 10px;
}
.gender-options {
display: flex;
justify-content: space-between;
}
.gender-options label {
display: inline;
margin-right: 10px;
}
</style>
</head>
<body>
<h1>Student Entry Form</h1>
<form action="#" method="post">
<label for="student-name">Student Name:</label>
<input type="text" id="student-name" name="studentName" required>
<label>Sex:</label>
<div class="gender-options">
<label><input type="radio" name="gender" value="Male" required> Male</label>
<label><input type="radio" name="gender" value="Female"> Female</label>
<label><input type="radio" name="gender" value="Other"> Other</label>
</div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Submit</button>
</form>
</body>
</html>
2.4 Output
PROGRAM -3
3.1 OBJECTIVE : Write programs using HTML and Java Script for validation of input
data
3.2 Introduction:
HTML Forms
HTML Forms are required to collect different kinds of user inputs, such as contact details like
name, email address, phone numbers, or detach like credit card information, etc.
Forms contain special elements called controls like input box, checkboxes, radio-buttons, submit
buttons, etc. Users generally complete a form by modifying as controls eg. entering text selecting
items, etc. and submitting this form to a web server for processing
The <form> tag is used to create an HTML form. Here's a simple example of a login form
Input Element
This is the most commonly used element within HTML forms. It allows you to specify various
types of user input fields, depending on the type attribute. An input clement can be of type test
field, password field, submit button, , etc. and several age input types introduced in HTML5
Password Field
Password fields are similar to text fields. The only difference is, characters in a password field are
masked i.e. shown as asterisks or dots. This is to prevent others from reading the password on the
screen. This is also a single-line text input controls created using an input element where type
attribute has a value of password
3.3 Code
<!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>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f9f9f9;
}
form {
max-width: 400px;
margin: auto;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 20px;
background-color: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
.error {
color: red;
font-size: 0.9em;
}
</style>
</head>
<body>
<h2 style="text-align: center;">Registration Form</h2>
<form id="registrationForm" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name">
<span id="nameError" class="error"></span>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email">
<span id="emailError" class="error"></span>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter a strong
password">
<span id="passwordError" class="error"></span>
3.4 Output
PROGRAM No -4
4.1 OBJECTIVE : Develop a responsive website using CSS and HTML. Website may be for
tutorial/blogs/commercial website.
4.2 Theory
Introduction:
Responsive web design is a technique used to create web pages that adjust their layout and content
dynamically based on the screen size and resolution of the user's device. This ensures optimal
viewing experiences across desktops, tablets, and mobile devices. CSS media queries play a crucial
role in designing responsive websites by allowing styles to be applied conditionally.
In this experiment, we will develop a responsive website suitable for a blog/tutorial platform. The
site will include a header, navigation menu, main content area, and a footer. The design will adapt
to different screen sizes for better usability.
HTML Structure
HTML provides the semantic structure of a web page. A basic responsive webpage has the
following main components:
1. Header: Contains the website logo and navigation menu.
2. Main Content: Includes articles, blog posts, or tutorials.
3. Sidebar (Optional): Displays additional links or ads.
4. Footer: Includes contact information and copyright notice
CSS and Media Queries
CSS is used to style the webpage, including layout adjustments, font styling, and colors. Media
queries are used to apply different styles depending on the screen size.
<!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="styles.css">
</head>
<body>
<header>
<div class="logo">My Blog</div>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section class="content">
<h1>Welcome to My Blog</h1>
<p>This is a responsive website designed to adjust to any screen size. It includes a header,
navigation, content section, and a footer.</p>
</section>
<aside class="sidebar">
<h2>Sidebar</h2>
<ul>
<li><a href="#">Recent Posts</a></li>
<li><a href="#">Categories</a></li>
<li><a href="#">Archives</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2024 My Blog. All rights reserved.</p>
</footer>
</body>
</html>
4.3 Cascading style sheet:
/* General Reset */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
}
/* Header Styles */
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background: #333;
color: white;
}
header .logo {
font-size: 1.5em;
font-weight: bold;
}
header nav ul {
list-style: none;
display: flex;
}
header nav ul li {
margin-left: 20px;
}
header nav ul li a {
text-decoration: none;
color: white;
padding: 5px 10px;
}
header nav ul li a:hover {
background: #555;
border-radius: 5px;
}
/* Main Content Styles */
main {
display: flex;
justify-content: space-between;
margin: 20px;
gap: 20px;
}
.content {
flex: 3;
padding: 20px;
background: #f9f9f9;
border-radius: 8px;
}
.sidebar {
flex: 1;
padding: 20px;
background: #efefef;
border-radius: 8px;
}
/* Footer Styles */
footer {
text-align: center;
padding: 20px;
background: #333;
color: white;
margin-top: 20px;
}
/* Responsive Design */
@media (max-width: 768px) {
header {
flex-direction: column;
text-align: center;
}
header nav ul {
flex-direction: column;
margin-top: 10px;
}
main {
flex-direction: column;
}
.content, .sidebar {
flex: 1;
}
}
4.4 Output
Program No - 5
5.1 Objective : 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.
5.2 Theory:
XML Document Type Declaration, commonly known as DTD, is a way to describe precisely the
XML language DTDs check the validity of structure and vocabulary of an XML document against
the grammatical rules of the appropriate XML language
Well-formed: If the XML document adheres to all the general XML rules such as tags must be
properly nested, opening and closing tags must be balanced, and emply tags must end with, then
it is called as well-formed
OR
Valid: An XML document said to be valid when it is not only well-formed, but it also conforms to
available DTD that specifies which tags it uses, what attributes those tags can contain, and which
tags can occur inside other tags, among other properties
5.3 Types:
DTD can be classified on its declaration basis in the XML document, such as
1.Internal DTD
2.External DTD
When a DTD is declared within the file it is called Internal DTD and if it is declared in a separate
file it is called External DTD
We will learn more about these in the chapter DTD Syntax
Syntax
declaration)
declaration2
In the above syntax
where rood-element is the name of root element and element-declarations is where you declare the
elements
Example
Following is a simple example of internal DTD
<address>
<name>Tanmay Patil</name>
<company>Tutorials Point/company
<phone>(011) 123-4567</phone>
</address>
5.5 XSLT : Extensible Stylesheet Language Transformation commonly awn as XBLT is a way to
transform the XML documents the forms such HTML as
<xsl: template> defines a way to reuse templates in order to generate the desired output for nodes
of a particular type/context .various template are used with the template like name, match, mode
priority.
<xsl: value-of> tag puts the value of the selected node as per XPath expression, as text.
Declaration : Following is the syntax declaration of <xsl:value-of> element.
<xsl :value-of
select Expression
disable - output-escaping = “Yes” | “no”>
</xsl :value-of>
<xsl:for - each> tag applies a template repeatedly for each node.
5.6 Declaration: Following is the syntax declaration of <xsl:for-each> element
<xsl:for- each
select Expression >
</xal:for- each>
<xsl:sort> tag specifies a sort criteria on the nodes.
Declaration
Following is the syntax declaration of <xsl: sort> element.
<xsl:sort
select string-expression
lang= { nmtoken }
data-type("text" | "number" | Qname }
order={“ascending”|”decending”}
Case-Order={“Upper-first” |”Lower – first”}>
</xsl:sort>
<xsl:if> tag specifies a conditional test against the content of nodes
Declaration
Following is the syntax declaration of <xsl:if> element.
<xsl:if
test = boolean-expression >
</xsl:if>
<xsl : choose> tag specified a multiple condition tests against the content of nodes in conjuction
with the <xsl : when > element .
Declaration Following is the syntax declaration of <xsl : choose> element
<xsl : choose>
</xsl : choose>
Output: In Internet Explorer
Title Artist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyer
5.7 XML
5.8 DTD
<!DOCTYPE note
[
!ELEMENT note (to ,form,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCADATA)><!ELEMENT heading (#(PCDATA)>
<!ELEMENT body (#PACDATA)>
]>
5.9 Output
This XML file does not appear to have any style information associated with it .The document tree
is shown below
<note>
<to> Tove </to>
,<from> Janir</from>
<heading> Reminder</heading>
<body> Don’t forget to me this weekend</body>
<footer> Writer : Donald Duck . copyright : W3school .</footer>
</note>
Program No 6
6.1 Objective : Create a Java Bean for Employee information (EmpID, Name, Salary,
Designation and Department)
6.2 Code
// Employee.java
import java.io.Serializable;
// Default Constructor
public Employee() {
}
// Parameterized Constructor
public Employee(int empID, String name, double salary, String designation, String department)
{
this.empID = empID;
this.name = name;
this.salary = salary;
this.designation = designation;
this.department = department;
}
// Employee.java
import java.io.Serializable;
// Parameterized Constructor
public Employee(int empID, String name, double salary, String designation, String department)
{
this.empID = empID;
this.name = name;
this.salary = salary;
this.designation = designation;
this.department = department;
}
#!/usr/bin/env node
USE user_db;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user_db", "root",
"yourpassword");
String sql = "INSERT INTO users (username, password, email, phone) VALUES (?, ?, ?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, username);
stmt.setString(2, password);
stmt.setString(3, email);
stmt.setString(4, phone);
if (rows > 0) {
out.println("<h2>Registration successful!</h2>");
} else {
out.println("<h2>Registration failed. Please try again.</h2>");
}
} catch (Exception e) {
out.println("<h2>Error: " + e.getMessage() + "</h2>");
} finally {
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}
%>
<a href="login.jsp">Go to Login</a>
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user_db", "root",
"yourpassword");
String sql = "SELECT * FROM users WHERE username = ? AND password = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, username);
stmt.setString(2, password);
rs = stmt.executeQuery();
if (rs.next()) {
out.println("<h2>Welcome, " + username + "!</h2>");
} else {
out.println("<h2>Invalid username or password. Please try again.</h2>");
}
} catch (Exception e) {
out.println("<h2>Error: " + e.getMessage() + "</h2>");
} finally {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}
%>
<a href="login.jsp">Go Back</a>
OutPut:
Program No : 9
9.1 Objective : 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.
const { MongoClient } = require('mongodb');
try {
// Connect to the MongoDB server
await client.connect();
console.log('Connected to MongoDB');
const db = client.db(dbName);
const usersCollection = db.collection('users'); // 'users' collection
9.2 Output
Program No - 10
10.1 Objective : Design and implement a simple shopping cart example with session tracking
API.
1. Session Management
Sessions allow the server to store user-specific data temporarily, such as the contents of their
shopping cart.
In this example, express-session is used to create and manage sessions for each user.
Each user's session is identified by a unique session ID, typically stored in a browser cookie
2. API Design
RESTful APIs are used to handle cart-related actions like adding items, removing items, and
viewing the cart.
Endpoints should be intuitive and follow HTTP methods (GET, POST, DELETE) for respective
operations.
5. Middleware
Middleware functions (like body parsers) process incoming requests to extract data or initialize
sessions.
// Start Server
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});
10.2 Output