Web Technology LAB Record
Web Technology LAB Record
Galgotias University
Web Technology
R1UC602C
Submitted To:
Mr. R.Radha Krishnan
1
21SCSE1011599
CERTIFICATE
STAFF-IN-CHARGE
2
21SCSE1011599
3
21SCSE1011599
Create and save an XML document at the server, which contains10 users 32 - 35
9. information. Write a program which takes user id as input and returns the
user details by taking the user informationfrom the XML document
10. Write a Servlet/ JSP program which takes value from HTML and print 36 - 37
using Servlet/ JSP.
11. Creating a JSP (JavaServer Pages) program that interacts with an Oracle 38 - 39
4
21SCSE1011599
Experiment 1
Design the following static web pages required for an online book store web site.
1. HOME PAGE: The static home page must contain three frames.
2. LOGIN PAGE
3. CATALOGUE PAGE: The catalogue page should contain the details of all the
books available in the web site in a table.
4. REGISTRATION PAGE
CODE
home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Online Book Store - Home</title>
<style>
frameset, frame {
border: none;
}
</style>
</head>
<frameset rows="15%,10%,*">
<frame src="header.html" name="header">
<frame src="nav.html" name="nav">
<frame src="content.html" name="content">
</frameset>
</html>
header.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #4682B4;
margin: 0;
color: white;
text-align: center;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
}
h1 {
margin: 20px 0;
}
</style>
</head>
<body>
<h1>📚 ONLINE BOOK STORE</h1>
</body>
</html>
content.html
<!DOCTYPE html>
5
21SCSE1011599
<html>
<head>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
text-align: center;
padding: 50px;
background-color: #fafafa;
}
h2 {
color: #333;
}
p {
font-size: 18px;
}
</style>
</head>
<body>
<h2>Explore Thousands of Books!</h2>
<p>Log in or register to start browsing and buying your favorite books online.</p>
</body>
</html>
catalogue.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
background-color: #fdfdfd;
padding: 30px;
}
h2 {
text-align: center;
color: #333;
}
table {
width: 90%;
margin: auto;
border-collapse: collapse;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
th, td {
padding: 12px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #4A90E2;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h2>Book Catalogue</h2>
<table>
<tr>
6
21SCSE1011599
<th>Book ID</th>
<th>Title</th>
<th>Author</th>
<th>Price</th>
<th>Genre</th>
</tr>
<tr>
<td>101</td>
<td>The Great Gatsby</td>
<td>F. Scott Fitzgerald</td>
<td>$10.99</td>
<td>Classic</td>
</tr>
<tr>
<td>102</td>
<td>1984</td>
<td>George Orwell</td>
<td>$8.99</td>
<td>Dystopian</td>
</tr>
<tr>
<td>103</td>
<td>Harry Potter</td>
<td>J.K. Rowling</td>
<td>$12.50</td>
<td>Fantasy</td>
</tr>
</table>
</body>
</html>
login.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
background-color: #f5f5f5;
text-align: center;
padding: 50px;
}
form {
background-color: white;
display: inline-block;
padding: 30px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
input[type="text"], input[type="password"] {
width: 250px;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
padding: 10px 20px;
border: none;
background-color: #4A90E2;
color: white;
font-weight: bold;
7
21SCSE1011599
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #357ABD;
}
</style>
</head>
<body>
<h2>User Login</h2>
<form>
<input type="text" name="username" placeholder="Username"><br>
<input type="password" name="password" placeholder="Password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
nav.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #f0f0f0;
text-align: center;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
padding: 10px;
}
a {
margin: 0 20px;
text-decoration: none;
font-weight: bold;
color: #333;
}
a:hover {
color: #4A90E2;
}
</style>
</head>
<body>
<a href="home.html" target="content">Home</a>
<a href="login.html" target="content">Login</a>
<a href="catalogue.html" target="content">Catalogue</a>
<a href="register.html" target="content">Register</a>
</body>
</html>
register.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
background-color: #f5f5f5;
text-align: center;
padding: 50px;
}
form {
8
21SCSE1011599
background-color: white;
display: inline-block;
padding: 30px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
input[type="text"], input[type="email"], input[type="password"] {
width: 250px;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
padding: 10px 20px;
border: none;
background-color: #4A90E2;
color: white;
font-weight: bold;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #357ABD;
}
</style>
</head>
<body>
<h2>Register New Account</h2>
<form>
<input type="text" name="fullname" placeholder="Full Name"><br>
<input type="email" name="email" placeholder="Email"><br>
<input type="text" name="username" placeholder="Username"><br>
<input type="password" name="password" placeholder="Password"><br>
<input type="password" name="confirm_password" placeholder="Confirm
Password"><br>
<input type="submit" value="Register">
</form>
</body>
</html>
9
21SCSE1011599
OUTPUT - SCREENSHOTS
HOME PAGE
LOGIN PAGE
10
21SCSE1011599
CATALOGUE PAGE
RAGISTRATION PAGE
11
21SCSE1011599
Experiment 2
CODE
registration.html
<!DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
background-color: #f0f0f0;
text-align: center;
padding: 50px;
}
form {
background-color: white;
display: inline-block;
padding: 30px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
input[type="text"], input[type="email"], input[type="password"], textarea {
width: 250px;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
padding: 10px 20px;
border: none;
background-color: #4A90E2;
color: white;
font-weight: bold;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #357ABD;
}
</style>
<script>
function validateForm() {
const fname = document.forms["regForm"]["firstname"].value.trim();
const lname = document.forms["regForm"]["lastname"].value.trim();
const email = document.forms["regForm"]["email"].value.trim();
12
21SCSE1011599
if (!nameRegex.test(fname)) {
errors.push("First name must be at least 6 alphabetic characters.");
}
if (!emailRegex.test(email)) {
errors.push("Please enter a valid email address (e.g. [email protected]).");
}
if (password.length < 6) {
errors.push("Password must be at least 6 characters long.");
}
if (!phoneRegex.test(phone)) {
errors.push("Phone number must be exactly 10 digits.");
}
if (errors.length > 0) {
alert(errors.join("\n"));
return false;
} else {
alert("🎉 Registration Successful!");
return true;
}
}
</script>
</head>
<body>
<h2>Register New Account</h2>
<form name="regForm" onsubmit="return validateForm()">
<input type="text" name="firstname" placeholder="First Name"><br>
<input type="text" name="lastname" placeholder="Last Name"><br>
<input type="email" name="email" placeholder="Email"><br>
<input type="password" name="password" placeholder="Password"><br>
<input type="text" name="phone" placeholder="Mobile Number"><br>
<textarea name="address" placeholder="Address"></textarea><br>
<input type="submit" value="Register">
</form>
</body>
</html>
13
21SCSE1011599
OUTPUT - SCREENSHOTS
14
21SCSE1011599
Experiment 3
Develop and demonstrate the usage of inline, internal and external style
sheet using CSS.
CODE
registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Styles Demo</title>
</body>
</html>
style.css
/* style.css */
.external-style {
color: #4A90E2;
font-weight: bold;
font-size: 16px;
font-family: Arial, sans-serif;
}
15
21SCSE1011599
OUTPUT - SCREENSHOTS
16
21SCSE1011599
Experiment 4
Develop and demonstrate JavaScript with POP-UP boxes and functions for the
following problems:
a) Input: Click on Display Date button using onclick( ) function
Output: Display date in the textbox
b) Input: A number n obtained using prompt
Output: Factorial of n number using alert
c) Input: A number n obtained using prompt
Output: A multiplication table of numbers from 1 to 10 of n using alert
d) Input: A number n obtained using prompt and add another number using
confirm
Output: Sum of the entire n numbers using alert
CODE
index.html
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Popup & Function Demo</title>
<style>
body {
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
padding: 30px;
background-color: #f4f4f4;
}
button {
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
margin: 10px;
padding: 10px 20px;
border: none;
background-color: #4CAF50;
color: white;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background-color: #45a049;
}
input {
padding: 10px;
margin-top: 10px;
width: 250px;
}
</style>
</head>
<body>
<script>
// Task 1: Display Date
function displayDate() {
document.getElementById("dateBox").value = new Date().toLocaleString();
}
let result = 1;
for (let i = 1; i <= n; i++) {
result *= i;
}
alert(output);
}
while (true) {
let n = parseFloat(prompt("Enter a number to add:"));
if (isNaN(n)) {
alert("Invalid input. Please enter a number.");
continue;
}
total += n;
count++;
18
21SCSE1011599
</body>
</html>
OUTPUT - SCREENSHOTS
19
21SCSE1011599
FIND FACTORIAL
MULTIPLICATION TABLE
20
21SCSE1011599
SUM OF NUMBERS
21
21SCSE1011599
Experiment 5
CODE
index.html
<!DOCTYPE html>
<html>
<head>
<title>Country Capital Selector</title>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
padding: 50px;
background-color: #f4f4f4;
}
label, select {
font-size: 18px;
}
#capitalDisplay {
margin-top: 20px;
font-size: 22px;
font-weight: bold;
color: #2E86C1;
}
</style>
<script>
function showCapital() {
const country = document.getElementById("countrySelect").value;
const capitalMap = {
India: "New Delhi",
USA: "Washington, D.C.",
France: "Paris",
Japan: "Tokyo",
Australia: "Canberra"
};
<option value="USA">USA</option>
<option value="France">France</option>
<option value="Japan">Japan</option>
<option value="Australia">Australia</option>
</select>
<div id="capitalDisplay"></div>
</body>
</html>
OUTPUT - SCREENSHOTS
23
21SCSE1011599
Experiment 6
CODE
index.html
<!DOCTYPE html>
<html>
<head>
<title>Number to Words (0 - 999)</title>
<style>
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida
Sans Unicode', Geneva, Verdana, sans-serif;
padding: 40px;
background-color: #f7f7f7;
}
input[type="text"] {
width: 200px;
padding: 10px;
font-size: 16px;
}
button {
padding: 10px 15px;
font-size: 16px;
margin-left: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background-color: #45a049;
}
#output {
margin-top: 20px;
font-weight: bold;
font-size: 20px;
color: #2E86C1;
}
</style>
</head>
<body>
<div id="output"></div>
<script>
const ones = ["zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine"];
const teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"];
24
21SCSE1011599
const tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"];
function convertToWords() {
let input = document.getElementById("numberInput").value.trim();
const output = document.getElementById("output");
// Convert to words
let words = "";
if (number === 0) {
words = "zero";
} else {
if (Math.floor(number / 100) > 0) {
words += ones[Math.floor(number / 100)] + " hundred";
if (number % 100 !== 0) {
words += " and ";
}
}
</body>
</html>
25
21SCSE1011599
OUTPUT - SCREENSHOTS
26
21SCSE1011599
Experiment 7
Create a form using various form elements and print the values using
Java Script
CODE
index.html
<!DOCTYPE html>
<html>
<head>
<title>Form Example</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
background-color: #f4f4f4;
}
label {
display: block;
margin-top: 15px;
font-weight: bold;
}
input[type="text"],
textarea,
select {
width: 300px;
padding: 8px;
margin-top: 5px;
font-size: 16px;
}
input[type="checkbox"],
input[type="radio"] {
margin-right: 5px;
}
button {
margin-top: 20px;
padding: 10px 15px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#output {
margin-top: 30px;
padding: 15px;
background: #fff;
border-left: 4px solid #2E86C1;
font-size: 16px;
white-space: pre-wrap;
}
</style>
</head>
<body>
27
21SCSE1011599
<h2>Registration Form</h2>
<form id="userForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label>Gender:</label>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
<label>Languages Known:</label>
<input type="checkbox" name="language" value="English">English
<input type="checkbox" name="language" value="Hindi">Hindi
<input type="checkbox" name="language" value="French">French
<label for="country">Country:</label>
<select id="country">
<option value="">--Select--</option>
<option value="India">India</option>
<option value="USA">USA</option>
<option value="UK">UK</option>
<option value="Australia">Australia</option>
</select>
<label for="comments">Comments:</label>
<textarea id="comments" rows="4"></textarea>
<div id="output"></div>
<script>
function printValues() {
let output = "";
const name = document.getElementById("name").value;
const country = document.getElementById("country").value;
const comments = document.getElementById("comments").value;
28
21SCSE1011599
document.getElementById("output").innerText = output;
}
</script>
</body>
</html>
OUTPUT - SCREENSHOTS
29
21SCSE1011599
Experiment 8
Write a AJAX program in which user will enter a number and table
of that will be displayed
CODE
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multiplication Table using JavaScript</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
background-color: #f4f4f4;
}
input[type="text"] {
padding: 10px;
font-size: 16px;
width: 200px;
}
button {
padding: 10px 15px;
font-size: 16px;
margin-left: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
}
#result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
white-space: pre-line;
color: #2E86C1;
}
</style>
</head>
<body>
<div id="result"></div>
<script>
function getTable() {
const num = document.getElementById("number").value;
document.getElementById("result").innerText = tableOutput;
}
</script>
</body>
</html>
OUTPUT - SCREENSHOTS
31
21SCSE1011599
Experiment 9
Create and save an XML document at the server, which contains10 users information.
Write a program which takes user id as input and returns the user details by taking
the user information from the XML document
CODE
users.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<id>1</id>
<name>John Doe</name>
<email>[email protected]</email>
<age>30</age>
</user>
<user>
<id>2</id>
<name>Jane Smith</name>
<email>[email protected]</email>
<age>25</age>
</user>
<user>
<id>3</id>
<name>Emily Johnson</name>
<email>[email protected]</email>
<age>35</age>
</user>
<user>
<id>4</id>
<name>Michael Brown</name>
<email>[email protected]</email>
<age>40</age>
</user>
<user>
<id>5</id>
<name>Chris Lee</name>
<email>[email protected]</email>
<age>28</age>
</user>
<user>
<id>6</id>
<name>Sarah Wilson</name>
<email>[email protected]</email>
<age>32</age>
</user>
<user>
<id>7</id>
<name>David Martinez</name>
<email>[email protected]</email>
<age>45</age>
</user>
<user>
<id>8</id>
<name>Rachel Adams</name>
<email>[email protected]</email>
<age>29</age>
</user>
<user>
32
21SCSE1011599
<id>9</id>
<name>Steven Clark</name>
<email>[email protected]</email>
<age>38</age>
</user>
<user>
<id>10</id>
<name>Olivia Turner</name>
<email>[email protected]</email>
<age>33</age>
</user>
</users>
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fetch User Details</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
background-color: #f4f4f4;
}
label {
font-size: 16px;
margin-right: 10px;
}
input[type="text"] {
padding: 8px;
font-size: 16px;
width: 200px;
}
button {
padding: 8px 15px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
white-space: pre-line;
color: #2E86C1;
}
</style>
</head>
<body>
<div id="result"></div>
<script>
function getUserDetails() {
const userId = document.getElementById("user_id").value;
// Loop through all users and find the user with the matching ID
for (let i = 0; i < users.length; i++) {
const user = users[i];
const id = user.getElementsByTagName("id")[0].textContent;
if (id == userId) {
const name = user.getElementsByTagName("name")[0].textContent;
const email = user.getElementsByTagName("email")[0].textContent;
const age = user.getElementsByTagName("age")[0].textContent;
userDetails = `
<h3>User Details</h3>
<p><strong>ID:</strong> ${id}</p>
<p><strong>Name:</strong> ${name}</p>
<p><strong>Email:</strong> ${email}</p>
<p><strong>Age:</strong> ${age}</p>
`;
break;
}
}
document.getElementById("result").innerHTML = userDetails;
}
};
xhr.send();
}
</script>
</body>
</html>
34
21SCSE1011599
OUTPUT - SCREENSHOTS
35
21SCSE1011599
Experiment 10
Write a Servlet/ JSP program which takes value from HTML and print using
Servlet/ JSP.
CODE
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Input Form</title>
</head>
<body>
<h2>Enter Your Details</h2>
<form action="userDetailsServlet" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required><br><br>
UserDetailsServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
displayUserDetails.jsp
36
21SCSE1011599
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Details</title>
</head>
<body>
<h2>User Details</h2>
<p><strong>Name:</strong> ${requestScope.name}</p>
<p><strong>Email:</strong> ${requestScope.email}</p>
<p><strong>Age:</strong> ${requestScope.age}</p>
</body>
</html>
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>UserDetailsServlet</servlet-name>
<servlet-class>UserDetailsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserDetailsServlet</servlet-name>
<url-pattern>/userDetailsServlet</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT - SCREENSHOTS
37
21SCSE1011599
Experiment 11
CODE
Table employees
INSERT INTO employees (id, name, department) VALUES (1, 'John Doe', 'Engineering');
INSERT INTO employees (id, name, department) VALUES (2, 'Jane Smith', 'Marketing');
INSERT INTO employees (id, name, department) VALUES (3, 'Emily Johnson', ‘HR');
displayEmployees.jsp
<%
// Database connection variables
String url = "jdbc:oracle:thin:@localhost:1521:orcl"; // Change to your DB
URL
String user = "your_db_user"; // Database username
String password = "your_db_password"; // Database password
// JDBC objects
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Load the JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");
38
21SCSE1011599
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>JSP Servlet</servlet-name>
<jsp-file>/displayEmployees.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>JSP Servlet</servlet-name>
<url-pattern>/displayEmployees.jsp</url-pattern>
</servlet-mapping>
</web-app>
39
21SCSE1011599
Experiment 12
To create a JSP (JavaServer Pages) program that prints the multiplication table
of a given number.
CODE
multiplicationTable.jsp
<%
// Get the number from the request
String numberStr = request.getParameter("number");
if (numberStr != null && !numberStr.isEmpty()) {
try {
int number = Integer.parseInt(numberStr);
out.println("<h3 style='text-align:center;'>Multiplication
Table of " + number + "</h3>");
out.println("<table>");
out.println("<tr><th>Multiplication</th><th>Result</th></
tr>");
out.println("</table>");
} catch (NumberFormatException e) {
out.println("<h3 style='color:red; text-
align:center;'>Please enter a valid number.</h3>");
}
}
%>
</body>
</html>
web.xml
OUTPUT - SCREENSHOTS
41
21SCSE1011599
Experiment 13
JSP program without session Management.
CODE
ExampleServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
example.jsp
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-
app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>ExampleServlet</servlet-name>
<servlet-class>ExampleServlet</servlet-class>
</servlet>
<servlet-mapping>
42
21SCSE1011599
<servlet-name>ExampleServlet</servlet-name>
<url-pattern>/example</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT - SCREENSHOTS
43
21SCSE1011599
Experiment 14
CODE
SessionExampleServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
RequestDispatcher dispatcher =
request.getRequestDispatcher("sessionExample.jsp");
dispatcher.forward(request, response);
}
}
sessionExample.jsp
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>SessionExampleServlet</servlet-name>
<servlet-class>SessionExampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SessionExampleServlet</servlet-name>
<url-pattern>/session-example</url-pattern>
</servlet-mapping>
</web-app>
44
21SCSE1011599
OUTPUT - SCREENSHOTS
45
21SCSE1011599
Experiment 15
CODE
form.jsp
welcome.jsp
FormServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
// Set the username in the request object for use in the JSP
request.setAttribute("username", username);
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
46
21SCSE1011599
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>FormServlet</servlet-name>
<servlet-class>FormServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormServlet</servlet-name>
<url-pattern>/formServlet</url-pattern>
</servlet-mapping>
</web-app
OUTPUT - SCREENSHOTS
47
21SCSE1011599
48