wt record
wt record
</body>
</html>
Output:
<table class="table1">
<colgroup>
<col span="2" style="background-color: red;">
<col span="2">
<col span="1" style="visibility: collapse;">
<col span="2" style="background-color: blue;">
</colgroup>
<tr>
<th>SUN</th>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 3
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
<th>SAT</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 4
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table>
<table class="table2">
<tr>
<th colspan="2">Name</th>
</tr>
<tr>
<th rowspan="2">Phone</th>
<td>usdighdds</td>
</tr>
<tr>
<td>989</td>
</tr>
</table>
<a href="https://en.wikipedia.org/wiki/Politician"><img src="https://shorturl.at/MbG7Z"
alt="Hello guys."></a>
</body>
</html>
.css:
table{
border: 2px solid black;
width: 70%;
align-items: center;
border-collapse: collapse;
}
.table1{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 20px;
padding: 15px;
}
.table1 td,th{
border: 0.5px solid green;
text-align: center;
}
.table1 tr:nth-child(even) {
background-color: magenta;
}
.table2{
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-
serif;
font-size: 15px;
margin: 10px;
padding: 5px;
width: 40%;
}
.table2 td,th{
border: 1px solid turquoise;
}
a:hover{
background-color: hotpink;
}
a{
text-decoration: none;
padding: 8px;
margin: 20px;
border: 1px solid crimson;
align-self: center;
}
Output:
Task-2:
CSS Styling: Apply CSS styling to enhance the visual appeal of the frames and content.
Use appropriate styles for fonts, colors, and layout.
Code:
Nav.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Navigation</title>
<link rel="stylesheet" href="styles.css">
</head>
<body id="nav">
<nav>
<ul>
Sidebar.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<nav>
<ul>
<li><a href="categories.html" target="content">categories</a></li>
<li><a href="bookdetails.html" target="content">books available</a></li>
</ul>
</nav>
</body>
</html>
Footer.html:
<!DOCTYPE html>
<html lang="en">
<head>
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 8
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Footer</title>
<link rel="stylesheet" href="styles.css">
</head>
<body id="footer">
<p>© 2025 Online Book Store. All rights reserved.</p>
</body>
</html>
Bookdetails.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Store</title>
<link rel="stylesheet" href="styles.css">
<script defer src="scripts.js"></script>
</head>
<body>
<h1>Book Store</h1>
<h2>Available Books</h2>
<div id="book-list" class="books">
<!-- Books will be loaded dynamically here -->
</div>
<h2>Shopping Cart</h2>
<div id="cart">
<ul id="cart-items"></ul>
<p id="cart-total">Total: 0 items</p>
</div>
</body>
</html>
Styles.css:
/* Global Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
display: flex;
flex-direction: column;
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 10
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
height: 100vh;
}
/* Navbar Styles */
.navbar {
background-color: #333;
padding: 10px 0;
text-align: center;
}
.navbar iframe {
width: 100%;
border: none;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
display: inline-block;
margin-right: 15px;
margin-left: 2px;
}
nav ul li a {
color: white;
text-decoration: none;
font-weight: bold;
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 11
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
nav ul li a:hover {
text-decoration: underline;
}
/* Content Layout */
.content {
display: flex;
height: 100%;
margin: 10px;
}
.content iframe {
border: none;
}
iframe[name="sidebar"] {
width: 250px;
height: 90%;
margin-top: 10px;
border: 1px solid crimson;
}
iframe[name="content"] {
flex: 1;
height: 100%;
padding: 30px;
}
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 12
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
/* Sidebar Styles */
nav ul li a {
color: #333;
}
nav ul li a:hover {
color: #007bff;
}
/* Footer Styles */
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
}
.footer p {
margin: 0;
}
p{
color: red;
font-size: 12px;
}
/* Books grid */
.books {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 13
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
}
.book {
padding: 15px;
border: 1px solid #ddd;
cursor: pointer;
text-align: center;
transition: transform 0.3s, box-shadow 0.3s;
}
.book:hover {
transform: translateY(-5px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
/* Book details */
#book-details {
margin-top: 20px;
padding: 20px;
border: 1px solid #ddd;
width: 50%;
}
#book-details p {
margin: 10px 0;
}
#add-to-cart:hover {
background-color: #218838;
}
/* Cart section */
#cart-items {
list-style-type: none;
padding: 0;
}
#cart-items li {
padding: 10px;
border-bottom: 1px solid #ddd;
}
Output:
DOM Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p{
font-size: 20px;
text-align: center;
}
h1{text-align: center;}
</style>
</head>
<body>
<h1>hi</h1>
<p>Hello</p>
<p id="d"></p>
<p id="c"></p>
<p id="b">old text</p>
<script>
document.getElementById('d').innerHTML="namaste";//inserting text
const element=document.getElementsByTagName('p');
document.getElementById('c').innerHTML="The text: "+element[0].innerHTML;//getting text
document.getElementById('b').innerHTML="new text";//changing text
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 16
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Validations:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Validation</title>
<script>
function isNotEmpty(value) {
return value.trim() !== "";
}
function isAllLetters(value) {
return /^[A-Za-z]+$/.test(value);
}
function isAllNumbers(value) {
return /^\d+$/.test(value);
}
function isFloatingNumber(value) {
return /^-?\d*\.?\d+$/.test(value);
}
function isAlphanumeric(value) {
return /^[A-Za-z0-9]+$/.test(value);
}
function isValidEmail(value) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
}
function isValidIPAddress(value) {
return /^(\d{1,3}\.){3}\d{1,3}$/.test(value);
}
function validateForm() {
let text = document.getElementById("text").value;
let number = document.getElementById("number").value;
let email = document.getElementById("email").value;
let ip = document.getElementById("ip").value;
alert(
`Not Empty: ${isNotEmpty(text)}\n` +
`All Letters: ${isAllLetters(text)}\n` +
`All Numbers: ${isAllNumbers(number)}\n` +
`Floating Number: ${isFloatingNumber(number)}\n` +
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 18
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
`Alphanumeric: ${isAlphanumeric(text)}\n` +
`Valid Email: ${isValidEmail(email)}\n` +
`Valid IP Address: ${isValidIPAddress(ip)}`
);
return false;
}
</script>
</head>
<body>
<form onsubmit="return validateForm()">
<label>Text: <input type="text" id="text"></label><br>
<label>Number: <input type="text" id="number"></label><br>
<label>Email: <input type="text" id="email"></label><br>
<label>IP Address: <input type="text" id="ip"></label><br>
<button type="submit">Validate</button>
</form>
</body>
</html>
Output:
<form id="loginForm">
<label for="loginUsername">Username</label>
<input type="text" id="loginUsername" name="username" placeholder="Username"><br>
<label for="loginPassword">Password</label>
<input type="password" id="loginPassword" name="password" placeholder="Password"><br>
</body>
</html>
Register.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="scripts.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<form id="registerForm">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Username">
<br>
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Password">
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 21
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
<br>
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="Re-
enter Password">
<br>
<input type="button" value="Register" onclick="validateForm()">
<p id="errorMsg" style="color: red;"></p>
</form>
</body>
</html>
Styles.css:
form {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 350px;
text-align: center;
}
input,
label {
margin: 8px 0;
padding: 8px;
width: 100%;
box-sizing: border-box;
}
input[type="text"],
input[type="password"] {
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="button"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 4px;
padding: 10px;
}
input[type="button"]:hover {
background-color: #45a049;
}
p{
color: red;
font-size: 12px;
}
Javascript:
function validateForm() {
let username = document.getElementById("username").value;
let password = document.getElementById("password").value;
let confirmPassword = document.getElementById("confirmPassword").value;
let errorMsg = document.getElementById("errorMsg");
if (username.length < 5) {
errorMsg.innerHTML = "Username must be at least 5 characters long.";
return;
}
if (password.length < 8) {
errorMsg.innerHTML = "Password must be at least 8 characters long.";
return;
}
localStorage.setItem('username', username);
localStorage.setItem('password', password);
alert("Registration Successful!");
window.location.href="login.html";
}
function validateLogin() {
let username1 = document.getElementById("loginUsername").value;
let password1 = document.getElementById("loginPassword").value;
let errorMsg = document.getElementById("loginErrorMsg");
let username=localStorage.getItem('username');
let password=localStorage.getItem('password');
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 24
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
// console.log(username)
// console.log(password)
if (password1.length < 8) {
errorMsg.innerHTML = "Password must be at least 8 characters long.";
return;
}
if(username!==username1 || password!==password1){
errorMsg.innerHTML="wrong user";
return;
}
alert("Login Successful!");
window.location.href="bookdetails.html";
}
description: "A journey of self-discovery through the eyes of a shepherd who seeks treasure in
Egypt.",
price: 15.99,
image: "https://m.media-amazon.com/images/I/51Z0nLAfLmL.jpg"
},
{
title: "1984",
author: "George Orwell",
description: "A dystopian novel about a totalitarian regime that controls every aspect of life.",
price: 12.99,
image: "https://m.media-amazon.com/images/I/41IXbIHb3-L.jpg"
},
{
title: "To Kill a Mockingbird",
author: "Harper Lee",
description: "A powerful novel about racial injustice and childhood in the Deep South.",
price: 14.49,
image: "https://m.media-amazon.com/images/I/81OthjkJBuL.jpg"
},
{
title: "The Great Gatsby",
author: "F. Scott Fitzgerald",
description: "A tragic love story set in the Roaring Twenties, filled with wealth and decadence.",
price: 10.99,
image: "https://m.media-amazon.com/images/I/71VJUD5hvxL.jpg"
},
{
title: "Moby Dick",
author: "Herman Melville",
description: "A thrilling tale of obsession and revenge between a sailor and a great white whale.",
price: 18.50,
image: "https://m.media-amazon.com/images/I/71A-9sHnY2L.jpg"
},
{
title: "Pride and Prejudice",
author: "Jane Austen",
description: "A timeless romance novel exploring love, class, and family in 19th-century
England.",
price: 9.99,
image: "https://m.media-amazon.com/images/I/91hhCXj9dbL.jpg"
},
{
title: "The Catcher in the Rye",
author: "J.D. Salinger",
description: "A story of teenage rebellion and self-identity told through the eyes of Holden
Caulfield.",
price: 13.25,
image: "https://m.media-amazon.com/images/I/81OthjkJBuL.jpg"
},
{
title: "The Hobbit",
author: "J.R.R. Tolkien",
description: "A fantasy adventure following Bilbo Baggins as he embarks on an epic quest.",
price: 16.75,
image: "https://m.media-amazon.com/images/I/91b0C2YNSrL.jpg"
}
];
function loadBooks() {
books.forEach((book, index) => {
const bookDiv = document.createElement("div");
bookDiv.classList.add("book");
bookDiv.textContent = book.title;
bookDiv.addEventListener("click", () => displayBookDetails(book, index));
bookList.appendChild(bookDiv);
});
}
addToCartBtn.style.display = "block";
function addToCart(book) {
cart.push(book);
updateCart();
}
function updateCart() {
cartItems.innerHTML = "";
cart.forEach((book, index) => {
const li = document.createElement("li");
li.textContent = `${book.title} - $${book.price.toFixed(2)}`;
cartItems.appendChild(li);
});
cartTotal.textContent = `Total: ${cart.length} items`;
}
document.addEventListener("DOMContentLoaded", loadBooks);
Output:
XML Structure and Design: Book Catalog XML: Design an XML structure to represent
the catalog of books in the online store. Include details such as book title, author,
genre, price, and availability.
books.xml:
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="books.xsd">
<book>
<title>The Alchemist</title>
<author>Paulo Coelho</author>
<description>A journey of self-discovery through the eyes of a shepherd who seeks treasure in
Egypt.</description>
<price>15.99</price>
<image>https://m.media-amazon.com/images/I/51Z0nLAfLmL.jpg</image>
</book>
<book>
<title>1984</title>
<author>George Orwell</author>
<description>A dystopian novel about a totalitarian regime that controls every aspect of
life.</description>
<price>12.99</price>
<image>https://m.media-amazon.com/images/I/41IXbIHb3-L.jpg</image>
</book>
<book>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<description>A powerful novel about racial injustice and childhood in the Deep
South.</description>
<price>14.49</price>
<image>https://m.media-amazon.com/images/I/81OthjkJBuL.jpg</image>
</book>
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<description>A tragic love story set in the Roaring Twenties, filled with wealth and
decadence.</description>
<price>10.99</price>
<image>https://m.media-amazon.com/images/I/71VJUD5hvxL.jpg</image>
</book>
<book>
<title>Moby Dick</title>
<author>Herman Melville</author>
<description>A thrilling tale of obsession and revenge between a sailor and a great white
whale.</description>
<price>18.50</price>
<image>https://m.media-amazon.com/images/I/71A-9sHnY2L.jpg</image>
</book>
<book>
<title>Pride and Prejudice</title>
<author>Jane Austen</author>
<description>A timeless romance novel exploring love, class, and family in 19th-century
England.</description>
<price>9.99</price>
<image>https://m.media-amazon.com/images/I/91hhCXj9dbL.jpg</image>
</book>
<book>
<title>The Catcher in the Rye</title>
<author>J.D. Salinger</author>
<description>A story of teenage rebellion and self-identity told through the eyes of Holden
Caulfield.</description>
<price>13.25</price>
<image>https://m.media-amazon.com/images/I/81OthjkJBuL.jpg</image>
</book>
<book>
<title>The Hobbit</title>
<author>J.R.R. Tolkien</author>
<description>A fantasy adventure following Bilbo Baggins as he embarks on an epic
quest.</description>
<price>16.75</price>
<image>https://m.media-amazon.com/images/I/91b0C2YNSrL.jpg</image>
</book>
</books>
books.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
<xs:element name="image" type="xs:anyURI"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
BookValidator.java:
package pro1;
import java.io.File;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.*;
// Validate
validator.validate(new StreamSource(xmlFile));
System.out.println("XML is valid against the XSD.");
} catch (Exception e) {
System.out.println("XML validation failed:");
System.out.println(e.getMessage());
}
}
}
Output:
<description></description>
<display-name>Helloworld</display-name>
<servlet-name>Helloworld</servlet-name>
<servlet-class>pro1.Helloworld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Helloworld</servlet-name>
<url-pattern>/Helloworld</url-pattern>
</servlet-mapping>
</web-app>
Output:
2. Init Parameters:
a. Single:
.java:
package pro1;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
public class Initparam extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
ServletConfig config=getServletConfig();
String name=config.getInitParameter("uname");
out.print("<html><body>");
out.print("<h2>Uname is: " + name + "</h2>");
out.print("</body></html>");
out.close();
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 38
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
}
}
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-
app_6_0.xsd" id="WebApp_ID" version="6.0">
<display-name>pro1</display-name>
<servlet>
<description></description>
<display-name>Initparam</display-name>
<servlet-name>Initparam</servlet-name>
<servlet-class>pro1.Initparam</servlet-class>
<init-param>
<param-name>uname</param-name>
<param-value>vnrvjiet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Initparam</servlet-name>
<url-pattern>/Initparam</url-pattern>
</servlet-mapping>
</web-app>
Output:
b. Enumeration:
.java:
package pro1;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
import java.util.*;
<init-param>
<param-name>email</param-name>
<param-value>[email protected]</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>InitparamEnum</servlet-name>
<url-pattern>/InitparamEnum</url-pattern>
</servlet-mapping>
</web-app>
Output:
3. Servlet parameters:
a. Single:
.java:
package pro1;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
public class ReadParam extends HttpServlet {
out.print("<html><body>");
out.print("<h2>Form Submission Results</h2>");
out.print("<p><b>Username:</b> " + username + "</p>");
out.print("<p><b>Email:</b> " + email + "</p>");
out.print("</body></html>");
out.close();
}
}
.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="ReadParam" method="post">
Username: <input type="text" name="username"><br>
Email: <input type="email" name="email"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Web.xml:
</servlet-mapping>
</web-app>
Output:
b. Enumeration:
.html:
<!DOCTYPE html>
<html>
<head>
<title>Servlet Parameter Example</title>
</head>
<body>
<h2>Enter Your Details</h2>
<form action="Servletenum" method="post">
Name: <input type="text" name="name"><br><br>
Email: <input type="email" name="email"><br><br>
Gender: <br>
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female
<br><br>
Country:
<select name="country">
<option value="USA">USA</option>
<option value="India">India</option>
<option value="UK">UK</option>
</select>
<br><br>
.java:
package pro1;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Retrieving parameters
String name = request.getParameter("name");
String email = request.getParameter("email");
String age = request.getParameter("age");
String gender = request.getParameter("gender");
String country = request.getParameter("country");
// Printing output
out.println("<html><body>");
out.println("<h2>User Details</h2>");
out.println("Name: " + name + "<br>");
out.println("Email: " + email + "<br>");
out.println("Age: " + age + "<br>");
out.println("Gender: " + gender + "<br>");
out.println("Country: " + country + "<br>");
out.println("</body></html>");
}
}
Web.xml:
<welcome-file-list>
<welcome-file>ParamFile.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>Servletenum</display-name>
<servlet-name>Servletenum</servlet-name>
<servlet-class>pro1.Servletenum</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servletenum</servlet-name>
<url-pattern>/Servletenum</url-pattern>
</servlet-mapping>
</web-app>
Output:
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
response.setContentType("text/html");
out.print("<html><body>");
out.print("<h2>Cookie Servlet</h2>");
if ("set".equalsIgnoreCase(action)) {
// Set a cookie
response.addCookie(cookie);
} else if ("get".equalsIgnoreCase(action)) {
if (cookies != null) {
out.print("<h3>Stored Cookies:</h3>");
} else {
} else if ("delete".equalsIgnoreCase(action)) {
if (cookies != null) {
if ("username".equals(cookie.getName())) {
cookie.setMaxAge(0); // Expire it
WEB TECHNOLOGIES LABORATORY 2022-26 BATCH 46
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
response.addCookie(cookie);
} else {
} else {
out.print("</body></html>");
out.close();
Web.xml:
<servlet>
<description></description>
<display-name>CookieServlet</display-name>
<servlet-name>CookieServlet</servlet-name>
<servlet-class>pro1.CookieServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CookieServlet</servlet-name>
<url-pattern>/CookieServlet</url-pattern>
</servlet-mapping>
Output:
out.println("<html><body>");
out.println("<h3>Hello " + name + ", your session is created.</h3>");
out.println("<a href='Second'>Go to Second Servlet</a>");
out.println("</body></html>");
}
}
Second.java:
package pro1;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
.html:
<!DOCTYPE html>
<html>
<head><title>HTTP Session</title></head>
<body>
<h2>Login using HTTP Session</h2>
<form action="First" method="post">
Name: <input type="text" name="name" required>
<input type="submit" value="Login">
</form>
</body>
</html>
Web.xml:
Output:
First.java:
package pro1;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
out.println("<html><body>");
out.println("<form action='Second'>");
out.println("<input type='hidden' name='user' value='" + name + "'>");
out.println("<input type='submit' value='Go to Second'>");
out.println("</form>");
out.println("</body></html>");
}
}
Second.java:
package pro1;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
.html:
<!DOCTYPE html>
<html>
<head><title>HTTP Session</title></head>
<body>
<h2>Login using HTTP Session</h2>
<form action="First" method="post">
Web.xml:
Output:
3. URL rewriting:
First.java:
package pro1;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
Second.java:
package pro1;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
out.println("<html><body>");
if (name != null && !name.isEmpty()) {
out.println("<h3>Welcome via URL Rewriting, " + name + "!</h3>");
} else {
out.println("<h3>No user data found in URL.</h3>");
}
out.println("</body></html>");
}
}
.html:
<!DOCTYPE html>
<html>
<head><title>HTTP Session</title></head>
<body>
<h2>Login</h2>
<form action="First" method="post">
Name: <input type="text" name="name" required>
<input type="submit" value="Login">
</form>
</body>
</html>
Web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" id="WebApp_ID" version="6.0">
<display-name>pro1</display-name>
<welcome-file-list>
<welcome-file>NewFile.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>First</display-name>
<servlet-name>First</servlet-name>
<servlet-class>pro1.First</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>First</servlet-name>
<url-pattern>/First</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>Second</display-name>
<servlet-name>Second</servlet-name>
<servlet-class>pro1.Second</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Second</servlet-name>
<url-pattern>/Second</url-pattern>
</servlet-mapping>
</web-app>
Output:
4. Request dispatcher:
First.java:
package pro1;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
RequestDispatcher rd = request.getRequestDispatcher("Second");
rd.forward(request, response);
}
}
Second.java:
package pro1;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
.html:
<!DOCTYPE html>
<html>
<head>
<title>Request Dispatcher Example</title>
</head>
<body>
<form action="First" method="post">
<label for="name">Enter your name:</label>
<input type="text" name="username" id="name" required>
<input type="submit" value="Submit">
</form>
</body>
</html>
Web.xml:
</servlet-mapping>
</web-app>
Output: