Web Lab Ex
Web Lab Ex
Page1.html
<!DOCTYPE html>
<html>
<head>
<title>Page 1</title>
</head>
<body>
<h1>This is Page 1</h1>
<p>Click the link below to go to Page 2:</p>
<a href="page2.html">Go to Page 2</a>
</body>
</html>
Page2.html
<!DOCTYPE html>
<html>
<head>
<title>Page 2</title>
</head>
<body>
<h1>This is Page 2</h1>
<p>You came from Page 1.</p>
<a href="page1.html">Back to Page 1</a>
</body>
</html>
Internal_nav.html
<!DOCTYPE html>
<html>
<head>
<title>Internal Navigation</title>
</head>
<body>
</body>
</html>
EX 2
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 30px;
}
input, select, button {
padding: 10px;
margin: 5px;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Simple Calculator</h1>
<form id="calcForm"
onsubmit="calculate(event)">
<input type="number" id="num1"
placeholder="Enter first number" required>
<button type="submit">Calculate</button>
</form>
<h2 id="result"></h2>
<script>
function calculate(event) {
event.preventDefault(); // Prevent page
reload
let num1 =
parseFloat(document.getElementById("num1").value);
let num2 =
parseFloat(document.getElementById("num2").value);
let op =
document.getElementById("operator").value;
let result;
switch (op) {
case '+': result = num1 + num2;
break;
case '-': result = num1 - num2;
break;
case '*': result = num1 * num2;
break;
case '/':
result = num2 !== 0 ? (num1 /
num2) : "Error: Division by zero";
break;
case '%':
result = num2 !== 0 ? (num1 %
num2) : "Error: Division by zero";
break;
default:
result = "Invalid operator";
}
document.getElementById("result").innerText =
"Result: " + result;
}
</script>
</body>
</html>
EX 3
College.html
<!DOCTYPE html>
<html>
<head>
<title>My College</title>
<h2>Contact Details</h2>
<table>
<tr>
<th>Office</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>Admin Office</td>
<td>[email protected]</td>
<td>+91-1234567890</td>
</tr>
<tr>
<td>Admission Cell</td>
<td>[email protected]</td>
<td>+91-9876543210</td>
</tr>
</table>
</body>
</html>
Styles.css
body {
font-family: Verdana, sans-serif;
background-color: #f0f4f8;
padding: 30px;
}
.main-heading {
color: #005a9c;
text-align: center;
border: 3px solid #005a9c;
padding: 10px;
border-radius: 10px;
background-color: #e0f0ff;
}
Ex 4
Person.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="person.xsl"?>
<people>
<person>
<name>John Doe</name>
<age>30</age>
<gender>Male</gender>
<email>[email protected]</email>
</person>
<person>
<name>Jane Smith</name>
<age>28</age>
<gender>Female</gender>
<email>[email protected]</email>
</person>
</people>
Person.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Person Information</title>
<style>
body { font-family: Arial;
background-color: #f0f0f0; padding: 20px; }
table { border-collapse: collapse;
width: 100%; }
th, td { border: 1px solid #999;
padding: 10px; text-align: left; }
th { background-color: #005a9c;
color: white; }
</style>
</head>
<body>
<h2>Person Information</h2>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Email</th>
</tr>
<xsl:for-each
select="people/person">
<tr>
<td><xsl:value-of
select="name"/></td>
Ex 5
Registration.html
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #eef2f3;
padding: 30px;
}
.form-container {
width: 400px;
background-color: #fff;
padding: 25px;
margin: auto;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h2 {
text-align: center;
color: #333;
}
input, select {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 6px;
}
input[type="submit"] {
background-color: #0077cc;
color: white;
border: none;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #005fa3;
}
</style>
</head>
<body>
<div class="form-container">
<h2>Registration Form</h2>
<form>
<label for="fullname">Full
Name:</label>
<input type="text" id="fullname"
name="fullname" required>
<label for="email">Email
Address:</label>
<input type="email" id="email"
name="email" required>
<label for="password">Password:</label>
<input type="password" id="password"
name="password" required>
<label for="gender">Gender:</label>
<select id="gender" name="gender"
required>
<option value="">--Select--
</option>
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select>
<label for="course">Course:</label>
<input type="text" id="course"
name="course">
</body>
</html>
EX 7
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Welcome to Our Website</h1>
<nav>
<ul>
<li><a href="about.html">About
Us</a></li>
<li><a href="services.html">Our
Services</a></li>
<li><a href="contact.html">Contact
Us</a></li>
</ul>
</nav>
</body>
</html>
About .html
<!DOCTYPE html>
<html>
<head>
<title>About Us</title>
</head>
<body>
<h1>About Us</h1>
<p>This page contains information about our
company.</p>
<a href="index.html">Back to Home</a>
</body>
</html>
Services.html
<!DOCTYPE html>
<html>
<head>
<title>Our Services</title>
</head>
<body>
<h1>Our Services</h1>
<p>Details about the services we offer.</p>
<a href="index.html">Back to Home</a>
</body>
</html>
Contact.html
<!DOCTYPE html>
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<h1>Contact Us</h1>
<p>Contact details and inquiry form.</p>
<a href="index.html">Back to Home</a>
</body>
</html>
EX 8
EmployeeLoginServlet.java
package servlet;
import jakarta.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/EmployeeLoginServlet")
public class EmployeeLoginServlet extends
HttpServlet {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("</body></html>");
}
login.html
<!DOCTYPE html>
<html>
<head>
<title>Employee Login</title>
</head>
<body>
<h2>Employee Login</h2>
<form action="EmployeeLoginServlet"
method="post">
<label for="username">Username:</label>
<input type="text" name="username"
id="username" required><br><br>
<label for="password">Password:</label>
<input type="password" name="password"
id="password" required><br><br>
EX 9
(i)
LoginServlet.java
package servlet;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import java.io.*;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException {
String username =
request.getParameter("username");
String password =
request.getParameter("password");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h3>Login Received</h3>");
out.println("Username: " + username +
"<br>");
out.println("Password: " + password +
"<br>");
out.println("</body></html>");
}
}
login.html
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<h2>Login Form</h2>
<form action="LoginServlet" method="post">
<label>Username:</label>
<input type="text" name="username"
required><br><br>
<label>Password:</label>
<input type="password" name="password"
required><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
(ii)
DataServlet.java
package servlet;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import java.io.*;
@WebServlet("/DataServlet")
public class DataServlet extends HttpServlet {
protected void doGet(HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println("Hello from Servlet! Data sent
to Applet.");
}
}
MyApplet.java
package servlet;
import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.net.*;
applet.html
<html>
<body>
<applet code="MyApplet.class" width="300"
height="100">
</applet>
</body>
</html>
EX 10
Login_js.html
<!DOCTYPE html>
<html>
<head>
<title>User Login Validation</title>
<script>
function validateLogin() {
const username =
document.forms["loginForm"]["username"].value.trim(
);
const password =
document.forms["loginForm"]["password"].value.trim(
);
document.getElementById("loginMsg").innerText =
"Login Successful!";
return false; // prevent form
submission for demonstration
}
</script>
</head>
<body>
<h2>User Login</h2>
<form name="loginForm" onsubmit="return
validateLogin()" method="post">
Username: <input type="text"
name="username"><br><br>
Password: <input type="password"
name="password"><br><br>
<input type="submit" value="Login">
</form>
<p id="loginMsg" style="color: green;"></p>
</body>
</html>
ii) registration_js.html
<!DOCTYPE html>
<html>
<head>
<title>Registration Form Validation</title>
<script>
function validateRegistration() {
const form = document.forms["regForm"];
const fullname =
form["fullname"].value.trim();
const email =
form["email"].value.trim();
const password =
form["password"].value;
const dob = form["dob"].value;
const gender = form["gender"].value;
document.getElementById("regMsg").innerText =
"Registered Successfully!";
return false; // prevent form
submission for demonstration
}
</script>
</head>
<body>
<h2>Registration Form</h2>
<form name="regForm" onsubmit="return
validateRegistration()" method="post">
Full Name: <input type="text"
name="fullname"><br><br>
Email: <input type="text"
name="email"><br><br>
Password: <input type="password"
name="password"><br><br>
Date of Birth: <input type="date"
name="dob"><br><br>
Gender:
<select name="gender">
<option value="">Select</option>
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select><br><br>
<input type="submit" value="Register">
</form>
<p id="regMsg" style="color: green;"></p>
</body>
</html>
EX 11
i)index.html
<!DOCTYPE html>
<html>
<head>
<title>Course: Web Development 101</title>
<style>
body {
font-family: 'Segoe UI', Tahoma,
Geneva, Verdana, sans-serif;
margin: 30px;
line-height: 1.6;
text-align: center;
}
</style>
<script>
function colorHeadings() {
const colors = ["#2E86C1", "#28B463",
"#CA6F1E", "#8E44AD", "#D68910", "#7F8C8D"];
for (let i = 1; i <= 6; i++) {
const headings =
document.getElementsByTagName("h" + i);
for (let j = 0; j <
headings.length; j++) {
headings[j].style.color =
colors[i - 1];
}
}
}
</script>
</head>
<body onload="colorHeadings()">
</body>
</html>
ii)index.html
<!DOCTYPE html>
<html>
<head>
<title>Article Styling with Headings</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
line-height: 1.6;
text-align: center;
}
h1 {
font-size: 36px;
color: red;
border-bottom: 2px solid #3498db;
margin-bottom: 10px;
}
h2 {
font-size: 30px;
color: blue;
margin-top: 30px;
}
h3 {
font-size: 24px;
color: green;
margin-top: 25px;
}
h4 {
font-size: 20px;
color: yellow;
}
h5 {
font-size: 18px;
color: orange;
}
h6 {
font-size: 16px;
color: purple;
font-style: italic;
}
</style>
</head>
<body>
<h1>Latest Tech Trends 2025</h1>
<p>Welcome to our annual tech trend report where
we analyze the upcoming changes in technology.</p>
<h4>Use Cases</h4>
<p>Radiology, surgery planning, drug discovery,
etc.</p>
<h5>Statistics</h5>
<p>Over 60% of hospitals are adopting AI tools in
diagnostics.</p>
<h6>Note</h6>
<p>This data is based on a global 2025
survey.</p>
</body>
</html>
EX 12
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Simple Centered Lists</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
padding: 20px;
background:pink;
}
.container {
text-align: center;
}
ol, ul, dl {
list-style-position: inside;
}
dt {
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>Types of Lists in HTML</h1>
<dt>CSS</dt>
<dd>A style sheet language used to describe
the look of a document written in HTML.</dd>
<dt>JavaScript</dt>
<dd>A scripting language that enables dynamic
content on web pages.</dd>
</dl>
</div>
</body>
</html>
EX 13
i)session.jsp
<html>
<body>
<%
visitCount = 1;
} else {
visitCount = visitCount + 1;
session.setAttribute("visitCount", visitCount);
%>
</body>
</html>
ii)
login.html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<h2>User Login</h2>
<form action="login.jsp" method="post">
Username: <input type="text"
name="username" required><br><br>
Password: <input type="password"
name="password" required><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
Login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Login Result</title>
</head>
<body>
<%
%>
<%
} else {
%>
<%
%>
</body>
</html>
EX 14
Track.php
<?php
// File to store the visitor count
$file = 'visitor_count.txt';
EX 15
Sort.php
<!DOCTYPE html>
<html>
<head>
<title>Merge and Sort Arrays</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 500px;
margin: 40px auto;
padding: 20px;
color: #222;
background-color: #fff;
}
.label {
font-weight: bold;
margin-top: 15px;
margin-bottom: 5px;
}
.code-block {
background-color: #f4f4f4;
border: 1px solid #ccc;
padding: 10px 12px;
border-radius: 4px;
font-family: monospace;
font-size: 16px;
}
.answer {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="label">array1:</div>
<div class="code-block">[3, 45, 2, 99]</div>
<div class="label">array2:</div>
<div class="code-block">[10, 56, 7, 20]</div>
<div class="answer">
Answer (merged & sorted descending):<br>
[<?= implode(', ', $merged) ?>]
</div>
</body>
</html>
EX 16
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Squares and Cubes Table</title>
<style>
table {
border-collapse: collapse;
width: 300px;
margin: 20px auto;
text-align: center;
font-family: Arial, sans-serif;
}
th, td {
border: 1px solid #333;
padding: 8px;
}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<script>
// Create the table element
let table = "<table>";
table +=
"<tr><th>Number</th><th>Square</th><th>Cube</th></t
r>";
table += "</table>";
</body>
</html>
EX 17
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Registration Form Validation</title>
<style>
body {
background-color: #eef7fa;
font-family: Arial, sans-serif;
}
.form-container {
width: 320px;
margin: 50px auto;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 8px rgba(0,0,0,0.1);
}
.form-container h2 {
text-align: center;
}
.error {
color: red;
font-size: 0.85em;
margin-bottom: 10px;
}
.success {
color: green;
font-weight: bold;
text-align: center;
margin-top: 10px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 6px;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
background-color: #28a745;
color: white;
font-weight: bold;
cursor: pointer;
border: none;
}
input[type="submit"]:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="form-container">
<h2>Registration Form</h2>
<form name="myForm" method="post"
onsubmit="return validateForm()">
<label>Name:</label>
<input type="text" name="name">
<div id="nameError" class="error"></div>
<label>Email:</label>
<input type="text" name="email">
<div id="emailError" class="error"></div>
<label>Age:</label>
<input type="text" name="age">
<div id="ageError" class="error"></div>
<label>Password:</label>
<input type="password" name="password">
<div id="passwordError" class="error"></div>
<script>
function validateForm() {
document.getElementById("successMessage").textConte
nt = "";
document.querySelectorAll(".error").forEach(el =>
el.textContent = "");
let isValid = true;
const name =
document.forms["myForm"]["name"].value.trim();
const email =
document.forms["myForm"]["email"].value.trim();
const age =
document.forms["myForm"]["age"].value.trim();
const password =
document.forms["myForm"]["password"].value;
document.getElementById('nameError').textContent =
"Name must be filled out.";
isValid = false;
}
const emailPattern =
/^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
document.getElementById('emailError').textContent =
"Please enter a valid email.";
isValid = false;
}
document.getElementById('ageError').textContent =
"Age must be a number between 1 and 120.";
isValid = false;
}
if (password.length < 6) {
document.getElementById('passwordError').textConten
t = "Password must be at least 6 characters.";
isValid = false;
}
if (isValid) {
document.getElementById("successMessage").textConte
nt = "Registration successful!";
document.forms["myForm"].reset(); // ←
Clear all input fields
}
</body>
</html>
EX 18
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Customer Details from XML</title>
<style>
body { font-family: Arial, sans-serif; padding:
20px; }
table { border-collapse: collapse; width: 100%;
max-width: 600px; margin: auto; }
th, td { border: 1px solid #ccc; padding: 8px;
text-align: left; }
th { background: #f4f4f4; }
caption { font-size: 1.2em; margin-bottom:
10px; }
</style>
</head>
<body>
<table id="customersTable">
<caption>Customer Details</caption>
<thead>
<tr>
<th>ID</th><th>Name</th><th>Email</th><th>Phone</th
><th>Address</th>
</tr>
</thead>
<tbody>
<!-- rows will be inserted here -->
</tbody>
</table>
<script>
// Fetch and parse the XML, then build the
table
fetch('customers_18.xml')
.then(response => response.text())
.then(xmlText => {
const parser = new DOMParser();
const xmlDoc =
parser.parseFromString(xmlText, "application/xml");
const rows = [];
xmlDoc.querySelectorAll('customer').forEach(cust =>
{
const id = cust.getAttribute('id');
const name =
cust.querySelector('name').textContent;
const email =
cust.querySelector('email').textContent;
const phone =
cust.querySelector('phone').textContent;
const addr =
cust.querySelector('address');
const street =
addr.querySelector('street').textContent;
const city =
addr.querySelector('city').textContent;
const state =
addr.querySelector('state').textContent;
const zip =
addr.querySelector('zip').textContent;
const fullAddr = `${street}, ${city},
${state} ${zip}`;
rows.push(`
<tr>
<td>${id}</td>
<td>${name}</td>
<td>${email}</td>
<td>${phone}</td>
<td>${fullAddr}</td>
</tr>
`);
});
document.querySelector('#customersTable
tbody').innerHTML = rows.join('');
})
.catch(err => {
console.error('Error loading XML:', err);
document.querySelector('#customersTable
tbody').innerHTML =
`<tr><td colspan="5">Failed to load
customer data.</td></tr>`;
});
</script>
</body>
</html>
Customer.xml
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer id="C001">
<name>John Doe</name>
<email>[email protected]</email>
<phone>+1-555-1234</phone>
<address>
<street>123 Elm Street</street>
<city>Springfield</city>
<state>IL</state>
<zip>62704</zip>
</address>
</customer>
<customer id="C002">
<name>Jane Smith</name>
<email>[email protected]</email>
<phone>+1-555-5678</phone>
<address>
<street>456 Oak Avenue</street>
<city>Lincoln</city>
<state>NE</state>
<zip>68508</zip>
</address>
</customer>
<!-- add more <customer> elements as needed -->
</customers>
EX 19
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Sort Integers Descending</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4faff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #fff;
padding: 20px 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
text-align: center;
}
input, button {
padding: 8px;
margin-top: 10px;
width: 100%;
box-sizing: border-box;
}
#result {
margin-top: 15px;
font-weight: bold;
color: green;
}
.error {
color: red;
}
</style>
</head>
<body>
<div class="container">
<h2>Sort Integers in Descending Order</h2>
<p>Enter numbers separated by commas (e.g.,
5,3,9,1):</p>
<input type="text" id="numbersInput"
placeholder="Enter integers here">
<button
onclick="sortDescending()">Sort</button>
<div id="result"></div>
</div>
<script>
function sortDescending() {
const input =
document.getElementById("numbersInput").value;
const resultDiv =
document.getElementById("result");
if (numberArray.some(isNaN)) {
resultDiv.innerHTML = "<span
class='error'>Please enter valid integers
only.</span>";
return;
}
EX 20
Index.jsp
<!DOCTYPE html>
<html>
<head>
<title>Enter Username</title>
</head>
<body>
<h2>Enter your name</h2>
<form action="cookie.jsp" method="get">
<input type="text" name="username"
required>
<input type="submit" value="Submit">
</form>
</body>
</html>
Cookie.jsp
<%
userCookie.setMaxAge(3600); // 1 hour
response.addCookie(userCookie);
// Retrieve cookie
if ("username".equals(c.getName())) {
savedUsername = c.getValue();
break;
%>
<!DOCTYPE html>
<html>
<head>
<title>Cookie Example</title>
</head>
<body>
<% } %>
</body>
</html>
*****************************************