Experiment 1: Write HTML/ java scripts to display your CV
in navigator , your institute website , department website
and tutorial website for specific subject.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My CV</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<div class="container">
<h1>KIRTI MISHRA</h1>
<p>Email: kirtimishra238@[Link] </p>
<p>Phone: 8318344489</p>
<h2>Education: third year</h2>
<p>Bachelor of Science in Computer Science – Anand Engineering College(2021-
2025)</p>
<h2>Experience</h2>
<p>Software Engineer - ABC Company (2019-Present)</p>
<h2>Skills</h2>
<ul>
<li>JavaScript</li>
<li>HTML/CSS</li>
<li>Python</li>
<li>Java</li>
</ul>
</div>
<script>
[Link]('DOMContentLoaded', function() {
[Link]('Document loaded');
});
</script>
</body>
</html>
Experiment 2: write an html program to design an entry
form of student details and send it to database server like
SQL, oracle or Ms access
HTML form ([Link]):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Details Entry Form</title>
</head>
<body>
<h2>Student Details Entry Form</h2>
<form action="[Link]" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email"><br><br>
<label for="dob">Date of Birth:</label><br>
<input type="date" id="dob" name="dob"><br><br>
<label for="gender">Gender:</label><br>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
PHP script to handle [Link]):
<?php
// Database connection parameters
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "student_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST['name'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$sql = "INSERT INTO students (name, email, dob, gender) VALUES ('$name', '$email',
'$dob', '$gender')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else { echo "Error: " . $sql . "<br>" . $conn->error;}
$conn->close();
?>
Experiment 3: write programs in javascript to display
browsers information
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Information</title>
</head>
<body>
<h2>Browser Information</h2>
<ul id="browser-info">
<li><strong>User Agent:</strong> <span id="user-agent"></span></li>
<li><strong>Browser:</strong> <span id="browser"></span></li>
<li><strong>Browser Version:</strong> <span id="browser-version"></span></li>
<li><strong>Operating System:</strong> <span id="os"></span></li>
</ul>
<script>
function getBrowserInfo() {
var userAgent = [Link];
var browser = '';
var version = '';
var os = '';
if ([Link]('Firefox') > -1) {
browser = 'Firefox';
version = [Link]('Firefox/')[1];
} else if ([Link]('Chrome') > -1) {
browser = 'Chrome';
version = [Link]('Chrome/')[1].split(' ')[0];
} else if ([Link]('Safari') > -1) {
browser = 'Safari';
version = [Link]('Version/')[1].split(' ')[0];
} else if ([Link]('MSIE') > -1 || [Link]('Trident') > -1) {
browser = 'Internet Explorer';
version = [Link]('MSIE ')[1].split(';')[0];
} else {
browser = 'Unknown';
version = 'Unknown';
}
if ([Link]('Windows') > -1) os = 'Windows';
else if ([Link]('Mac') > -1) os = 'Macintosh';
else if ([Link]('Linux') > -1) os = 'Linux';
else if ([Link]('Android') > -1) os = 'Android';
else if ([Link]('iOS') > -1) os = 'iOS';
else os = 'Unknown';
[Link]('user-agent').innerText = userAgent;
[Link]('browser').innerText = browser;
[Link]('browser-version').innerText = version;
[Link]('os').innerText = os;
}getBrowserInfo();
</script></body></html>
Experiment 4: write a java applet to display the
application [Link]
Code:
import [Link];
import [Link].*;
import [Link].*;
public class CalculatorApplet extends Applet implements ActionListener {
TextField display;
Button buttons[];
String buttonTexts[] = {"7", "8", "9", "+", "4", "5", "6", "-", "1", "2", "3", "*", "C", "0",
"=", "/"};
char operator;
double num1, num2, result;
public void init() {
display = new TextField(10);
[Link](false);
add(display);
buttons = new Button[[Link]];
for (int i = 0; i < [Link]; i++) {
buttons[i] = new Button(buttonTexts[i]);
buttons[i].addActionListener(this);
add(buttons[i]);
}}
public void actionPerformed(ActionEvent ae) {
String command = [Link]();
if ([Link](0) >= '0' && [Link](0) <= '9' || [Link](".")) {
[Link]([Link]() + command);
} else if ([Link]("C")) [Link]("");
} else if ([Link]("+") || [Link]("-") || [Link]("*") ||
[Link]("/")) {
num1 = [Link]([Link]());
operator = [Link](0);
[Link]("");
} else if ([Link]("=")) {
num2 = [Link]([Link]());
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;}
[Link]([Link](result)); }}}
To run this applet, compile it using javac [Link], then create an HTML
file to embed the applet:
<!DOCTYPE html>
<html>
<head>
<title>Calculator Applet</title>
</head>
<body>
<applet code="[Link]" width="300" height="300">
</applet>
</body>
</html>
Experiment 5: writing program in xml for creation of DTD ,
which specifies set of rules create a style sheet in css/xsl
and display the document in internet explorer
Create an XML document ([Link]):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data SYSTEM "[Link]">
<data>
<person>
<name>John Doe</name>
<age>30</age>
</person>
<person>
<name>Jane Smith</name>
<age>25</age>
</person>
</data>
Create a DTD ([Link]):
<!ELEMENT data (person+)>
<!ELEMENT person (name, age)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT age (#PCDATA)>
Create a CSS stylesheet ([Link]):
person {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
name {
font-weight: bold;
}
age {
color: blue;
}
Create an XSL stylesheet (Optional) ([Link]):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[Link]
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="[Link]"/>
</head>
<body>
<xsl:apply-templates select="data"/>
</body>
</html>
</xsl:template>
<xsl:template match="data">
<xsl:apply-templates select="person"/>
</xsl:template>
<xsl:template match="person">
<div class="person">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="name">
<h2><xsl:value-of select="."/></h2>
</xsl:template>
<xsl:template match="age">
<p><xsl:value-of select="."/></p>
</xsl:template>
</xsl:stylesheet>
Display the document in Internet Explorer:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="[Link]"?>
<!DOCTYPE data SYSTEM "[Link]">
<data>
<!-- XML data goes here -->
</data>
This will transform the XML data using the XSL stylesheet before displaying it in the
browser.
Experiment 6: program to illustrate jdbc connectivity .
design and implement a simple servelet book query with
the help of jdbc and sql . create ms access database ,
create an odbc link ,compile and execute java jdvc socket
and with the output also
Create an MS Access Database:
Open Microsoft Access and create a new database (e.g., [Link]).
Create a table named books with columns like id, title, author, price, etc.
Populate the table with some sample data.
Create an ODBC Data Source:
Go to Control Panel > Administrative Tools > Data Sources (ODBC).
Under the User DSN or System DSN tab, click Add and select Microsoft Access
Driver (*.mdb, *.accdb).
Set the Data Source Name (DSN) and select the database file ([Link]) you
created.
Click OK to create the ODBC data source.
Java JDBC Connectivity:
Write Java code to establish a JDBC connection to the MS Access database and perform
queries.
CODE:
import [Link].*;
public class JDBCExample {
public static void main(String[] args) {
try {
Connection conn = [Link]("jdbc:odbc:BooksDB");
Statement stmt = [Link]();
ResultSet rs = [Link]("SELECT * FROM books");
while ([Link]()) {
[Link]([Link]("id") + "\t" +
[Link]("title") + "\t" +
[Link]("author") + "\t" +
[Link]("price"));
}
[Link]();
[Link]();
[Link]();
} catch (Exception e) {
[Link]();
}
}
}
Servlet with JDBC:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class BookQueryServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
try {
Connection conn = [Link]("jdbc:odbc:BooksDB");
Statement stmt = [Link]();
ResultSet rs = [Link]("SELECT * FROM books");
[Link]("<html><head><title>Book Query Results</title></head><body>");
[Link]("<h1>Book Query Results</h1>");
[Link]("<table
border='1'><tr><th>ID</th><th>Title</th><th>Author</th><th>Price</th></tr>");
while ([Link]()) {
[Link]("<tr><td>" + [Link]("id") + "</td>" +
"<td>" + [Link]("title") + "</td>" +
"<td>" + [Link]("author") + "</td>" +
"<td>" + [Link]("price") + "</td></tr>");
}
[Link]("</table></body></html>");
[Link]();
[Link]();
[Link]();
} catch (Exception e) {
[Link]();
}
}
}
Compile and Execute:
Compile the Java code ([Link] and [Link]) using javac.
Deploy the servlet ([Link]) to a servlet container like Apache
Tomcat.
Access the servlet URL in a web browser to see the book query results.
Experiment 7:install tomcat web server and apache.
Access the above developed static web pages for books
website using localhost url.
Installing Tomcat and Accessing Static Web Pages
Preparation:
1. Download Software:
o Downloading Tomcat from: [Link]
o Downloading Apache from: [Link]
2. Locate Static Web Pages:
o Then Finally accessed the book website from here.
A. Installing Tomcat:
1. Extract Tomcat:
o Extract the downloaded Tomcat archive to a desired location
2. Start Tomcat:
o Navigate to the Tomcat bin directory:
cd /opt/tomcat/bin
o Run the startup script:
[Link]
3. Verify Tomcat Installation:
o Opened web browser and went to [Link] Saw the Tomcat
welcome page.
B. Accessing Static Web Pages:
1. Placing HTML Files:
o Copied HTML files to the Tomcat webapps directory:
o /opt/tomcat/webapps/books_website
2. Restarting Tomcat:
After placing files, restart Tomcat using the shutdown and startup scripts:
[Link]
[Link]
3. Accessing in Browser:
o Opened web browser and went to [Link]
Finally saw our books website!
Experiment 8: Assume four users user1, user2, user3,
user4 having the passwords pwd1,pwd2,pwd3,pwd4
respectively . write a servlet for doing the following .
create a cookie and add these four user id's and
passwords to this cookie . and read the user id and
passwords entered in the login form and authenticate with
the values available in the cookies.
Code:
import [Link].*;
import [Link].*;
import [Link].*;
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
String userId = [Link]("userId");
String password = [Link]("password");
Cookie cookie = new Cookie("UserCredentials", userId + ":" + password);
[Link](3600); // Cookie expires in 1 hour
[Link](cookie);
[Link]("<html><head><title>Login Result</title></head><body>");
boolean authenticated = false;
Cookie[] cookies = [Link]();
if (cookies != null) {
for (Cookie c : cookies) {
if ([Link]().equals("UserCredentials")) {
String[] values = [Link]().split(":");
if ([Link](values[0]) && [Link](values[1])) {
authenticated = true;
break;
}
}
}
}
if (authenticated) {
[Link]("<h2>Welcome, " + userId + "!</h2>");
[Link]("<p>You are successfully logged in.</p>");
} else {
[Link]("<h2>Authentication failed!</h2>");
[Link]("<p>Invalid user ID or password.</p>");
}
[Link]("</body></html>");
}
}
Experiment 9: Install a database (mysql or oracle) . create
a table which should contain at least the following fields :
name, password, email-id, phone number. write a java
program /servlet/jsp to connect to that database and
extract data from the tables and display them, insert the
details of the user who register with the website
whenever a new user clicks the submit button in the
registration page.
Install and Set Up MySQL Database:
CREATE DATABASE userdb;
USE userdb;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
phone VARCHAR(15) NOT NULL
);
Write Java Servlet to Connect to the Database and Extract Data:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class UserServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
try {
[Link]("[Link]");
Connection conn = [Link]("jdbc:mysql://localhost:3306/userdb",
"username", "password");
Statement stmt = [Link]();
ResultSet rs = [Link]("SELECT * FROM users");
[Link]("<html><head><title>User Information</title></head><body>");
[Link]("<h2>User Information</h2>");
[Link]("<table
border='1'><tr><th>Name</th><th>Email</th><th>Phone</th></tr>");
while ([Link]()) {
[Link]("<tr><td>" + [Link]("name") + "</td>" +
"<td>" + [Link]("email") + "</td>" +
"<td>" + [Link]("phone") + "</td></tr>"); }
[Link]("</table></body></html>");
[Link]();
[Link]();
[Link]();
} catch (Exception e) {
[Link](); }}}
Write Java Servlet/JSP for User Registration:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class RegisterServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
String name = [Link]("name");
String password = [Link]("password");
String email = [Link]("email");
String phone = [Link]("phone");
try {
[Link]("[Link]");
Connection conn =
[Link]("jdbc:mysql://localhost:3306/userdb", "username",
"password");
PreparedStatement pstmt = [Link]("INSERT INTO users (name,
password, email, phone) VALUES (?, ?, ?, ?)");
[Link](1, name);
[Link](2, password);
[Link](3, email);
[Link](4, phone);
int rowsAffected = [Link]();
if (rowsAffected > 0) {
[Link]("<html><head><title>Registration Success</title></head><body>");
[Link]("<h2>Registration Success</h2>");
[Link]("<p>User registered successfully!</p>");
[Link]("</body></html>");
} else {
[Link]("<html><head><title>Registration Failed</title></head><body>");
[Link]("<h2>Registration Failed</h2>");
[Link]("<p>Failed to register user. Please try again.</p>");
[Link]("</body></html>"); }
[Link]();
[Link]();
} catch (Exception e) {
[Link]();
[Link]("<html><head><title>Error</title></head><body>");
[Link]("<h2>Error</h2>");
[Link]("<p>An error occurred while processing your request. Please try again
later.</p>");
[Link]("</body></html>"); }}}
Experiment 10: Write a JSP which inserts the details of 3
or 4 users who register with the website by using
registration form. Authenticate the user when he submits
the login form using the username and password from the
database.
[Link]
<%@ page import="[Link].*" %>
<jsp:useBean id="dbConfig" class="[Link]" scope="application">
<jsp:setProperty name="dbConfig" property="url"
value="jdbc:mysql://localhost:3306/your_database_name" />
<jsp:setProperty name="dbConfig" property="username" value="your_username" />
<jsp:setProperty name="dbConfig" property="password" value="your_password" />
</jsp:useBean>
<%
String name = [Link]("name");
String email = [Link]("email");
String username = [Link]("uname");
String password = [Link]("psw");
Connection connection = null;
try {
connection = [Link]();
} catch (Exception e) {
[Link]("<b>Database connection error: " + [Link]() + "</b>");
return; // Exit if connection fails
}
if (connection != null && name != null && email != null && username != null &&
password != null) {
try {
String sql = "INSERT INTO users (name, email, username, password) VALUES
(?, ?, ?, ?)";
PreparedStatement statement = [Link](sql);
[Link](1, name);
[Link](2, email);
[Link](3, username);
[Link](4, password);
int rowsInserted = [Link]();
if (rowsInserted > 0) {
[Link]("<b>User registration successful!</b>");
} else {
[Link]("<b>User registration failed!</b>");
}
} catch (SQLException e) {
[Link]("<b>Error: " + [Link]() + "</b>");
} finally {
try {
[Link](); // Ensure connection is closed even on errors
} catch (SQLException e) {
[Link]("<b>Error closing connection: " + [Link]() + "</b>");}}
} else [Link]("<b>Please fill out the registration form.</b>");
%>
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h1>User Registration</h1>
<form action="[Link]" method="post">
Name: <input type="text" name="name" required><br><br>
Email: <input type="email" name="email" required><br><br>
Username: <input type="text" name="uname" required><br><br>
Password: <input type="password" name="psw" required><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>
[Link]
<%@ page import="[Link].*" %>
<jsp:useBean id="dbConfig" class="[Link]" scope="application">
<jsp:setProperty name="dbConfig" property="url"
value="jdbc:mysql://localhost:3306/your_database_name" />
<jsp:setProperty name="dbConfig" property="username" value="your_username" />
<jsp:setProperty name="dbConfig" property="password" value="your_password" />
</jsp:useBean>
<%
String loginUsername = [Link]("uname");
String loginPassword = [Link]("psw");
String message = "";
<%
Connection connection = null;
try {
connection = [Link]();
} catch (Exception e) {
message = "<b>Database connection error: " + [Link]() + "</b>";
return; }
if (connection != null && loginUsername != null && loginPassword != null) {
try {
String sql = "SELECT * FROM users WHERE username = ? AND password = ?";
PreparedStatement statement = [Link](sql);
[Link](1, loginUsername);
[Link](2, loginPassword);
ResultSet resultSet = [Link]();
if ([Link]()) {
message = "<b>Login successful! Welcome, " + [Link]("name") +"</b>";
[Link]("username", loginUsername);
} else message = "<b>Invalid username or password.</b>";
[Link]();
} catch (SQLException e) {
message = "<b>Error: " + [Link]() + "</b>";
} finally {
try {
[Link](); // Ensure connection is closed even on errors
} catch (SQLException e) {
message = message + "<br><b>Error closing connection: " + [Link]() + "</b>"; }}
} else message = "<b>Please enter your username and password.</b>";
%>
<!DOCTYPE html>
<html>
<head>
<title>User Login</title>
</head>
<body>
<h1>User Login</h1>
<%= message %>
<form action="[Link]" method="post">
Username: <input type="text" name="uname" required><br><br>
Password: <input type="password" name="psw" required><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
Experiment 11: Design and implement a simple shopping
cart example with session tracking API
[Link]
public class Product {
private int id;
private String name;
private double price;
private int quantity;
}
[Link]
import [Link];
import [Link];
public class Cart {
private Map<Integer, Product> items;
public Cart() {
items = new HashMap<>();
}
public void addItem(Product product, int quantity) {
if ([Link]([Link]())) {
[Link]([Link]()).setQuantity([Link]([Link]()).getQuantity() +
quantity);
} else {
[Link](quantity);
[Link]([Link](), product);
}
}
public void removeItem(Product product) {
[Link]([Link]());
}
public void updateQuantity(Product product, int quantity) {
[Link](quantity);
[Link]([Link](), product);
}
public Map<Integer, Product> getItems() {
return items;
}
public double getTotalPrice() {
double totalPrice = 0;
for (Product product : [Link]()) {
totalPrice += [Link]() * [Link]();
}
return totalPrice;
}
}
ProductServlet
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet("/products")
public class ProductServlet extends HttpServlet {
private List<Product> products = new ArrayList<>();
@Override
public void init() throws ServletException {
[Link](new Product(1, "Product 1", 10.00, 0));
[Link](new Product(2, "Product 2", 20.00, 0));
[Link](new Product(3, "Product 3", 30.00, 0));
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
HttpSession session = [Link](true); // Create session if not existing
Cart cart = (Cart) [Link]("cart");
if (cart == null) {
cart = new Cart();
[Link]("cart", cart);
}
[Link]("products", products);
[Link]("/[Link]").forward(request, response);
}
}
CartServlet
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet("/cart")
public class CartServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
int productId = [Link]([Link]("productId"));
String action = [Link]("action");
int quantity = 1; // Default quantity
if ([Link]("quantity") != null) {
quantity = [Link]([Link]("quantity"));
}
HttpSession session = [Link]();
Cart cart = (Cart) [Link]("cart");
if (cart == null) {
cart = new Cart();
[Link]("cart", cart);
}
switch (action) {
case "add":
[Link](getProductById(productId), quantity);
break;
case "remove":
[Link](getProductById(productId));
break;
case " "update":
[Link](getProductById(productId), quantity);
break;
default:
break; } }
private Product getProductById(int productId) {
return new Product(productId, "Sample Product", 10.00, 0); } }