0% found this document useful (0 votes)
3 views

advanced_java_updated

The document contains multiple Java programs demonstrating various concepts such as ArrayLists, random number generation, user-defined classes, string manipulation, StringBuffer methods, Swing event handling, and servlet creation for greeting users. Each program is accompanied by its source code and expected output. The examples illustrate fundamental programming techniques in Java, including data structures, GUI development, and web applications.

Uploaded by

Mohammed Fahad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

advanced_java_updated

The document contains multiple Java programs demonstrating various concepts such as ArrayLists, random number generation, user-defined classes, string manipulation, StringBuffer methods, Swing event handling, and servlet creation for greeting users. Each program is accompanied by its source code and expected output. The examples illustrate fundamental programming techniques in Java, including data structures, GUI development, and web applications.

Uploaded by

Mohammed Fahad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

1.

Implement a java program to demonstrate creating an ArrayList, adding elements,


removing elements, sorting elements of ArrayList. Also illustrate the use of toArray()
method

import java.util.ArrayList;
import java.util.Collections;

public class ArrayListDemo {


public static void main(String[] args) {
// Create an ArrayList
ArrayList<Integer> numbers = new ArrayList<>();

// Adding elements to the ArrayList


numbers.add(5);
numbers.add(2);
numbers.add(8);
numbers.add(3);

// Displaying elements of the ArrayList


System.out.println("ArrayList elements: " + numbers);

// Removing an element from the ArrayList


numbers.remove(2); // Removes the element at index 2

// Displaying elements of the ArrayList after removal


System.out.println("ArrayList elements after removing element at index 2: " + numbers);

// Sorting elements of the ArrayList


Collections.sort(numbers);

// Displaying elements of the ArrayList after sorting


System.out.println("ArrayList elements after sorting: " + numbers);

// Illustrating the use of toArray() method


Integer[] arr = numbers.toArray(new Integer[numbers.size()]);

// Displaying elements of the array obtained from ArrayList


System.out.print("Array obtained from ArrayList: ");
for (Integer num : arr) {
System.out.print(num + " ");
}
System.out.println();
}
}
OUTPUT
________________

ArrayList elements: [5, 2, 8, 3]


ArrayList elements after removing element at index 2: [5, 2, 3]
ArrayList elements after sorting: [2, 3, 5]
Array obtained from ArrayList: 2 3 5
2.Develop a program to read random numbers between a given range that are
multiples of 2 and 5, sort the numbers according to tens place using comparator.

import java.util.*;

// Define a comparator to sort numbers based on tens place


class TensPlaceComparator implements Comparator<Integer> {
@Override
public int compare(Integer num1, Integer num2) {
int tensPlace1 = (num1 % 100) / 10;
int tensPlace2 = (num2 % 100) / 10;
return Integer.compare(tensPlace1, tensPlace2);
}
}

public class Main {

// Method to generate random numbers between a given range that are multiples of 2 and 5
public static List<Integer> generateNumbers(int start, int end, int count) {
List<Integer> numbers = new ArrayList<>();
Random random = new Random();
while (numbers.size() < count) {
int num = random.nextInt(end - start + 1) + start;
if (num % 2 == 0 && num % 5 == 0) {
numbers.add(num);
}
}
return numbers;
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

// Input range and count of random numbers


System.out.print("Enter the start of the range: ");
int startRange = scanner.nextInt();
System.out.print("Enter the end of the range: ");
int endRange = scanner.nextInt();
System.out.print("Enter the number of random multiples of 2 and 5 to generate: ");
int count = scanner.nextInt();

// Generate random numbers


List<Integer> numbers = generateNumbers(startRange, endRange, count);
System.out.println("Generated numbers: " + numbers);

// Sort the numbers based on tens place using comparator


Collections.sort(numbers, new TensPlaceComparator());

// Display sorted numbers


System.out.println("Sorted numbers based on tens place:");
for (int num : numbers) {
System.out.println(num);
}
}
}
OUTPUT

Enter the start of the range: 10 20


Enter the end of the range: Enter the number of random multiples of 2 and 5 to generate: 4
Generated numbers: [20, 10, 10, 10]
Sorted numbers based on tens place:
10
10
10
20
3.Implement a java program to illustrate storing user defined classes in collection.
import java.util.ArrayList;
// Define a user-defined class
class User {
private String username;
private String email;

// Constructor
public User(String username, String email) {
this.username = username;
this.email = email;
}

// Getters and setters


public String getUsername() {
return username;
}

public void setUsername(String username) {


this.username = username;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}
// Override toString method to display user information
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", email='" + email + '\'' +
'}';
}
}

public class Main {


public static void main(String[] args) {
// Create a collection to store User objects
ArrayList<User> users = new ArrayList<>();

// Create some User objects


User user1 = new User("JohnDoe", "[email protected]");
User user2 = new User("JaneDoe", "[email protected]");
User user3 = new User("Alice", "[email protected]");

// Add User objects to the collection


users.add(user1);
users.add(user2);
users.add(user3);

// Display all users in the collection


System.out.println("Users in the collection:");
for (User user : users) {
System.out.println(user);
}
}
}
Output
-------------
Users in the collection:
User{username='JohnDoe', email='[email protected]'}
User{username='JaneDoe', email='[email protected]'}
User{username='Alice', email='[email protected]'}
4. Implement a java program to illustrate the use of different types of string class
constructors.
public class Main {
public static void main(String[] args) {
// Using string literals
String str1 = "Hello, World!"; // Using string literal
System.out.println("String using string literal: " + str1);

// Using new keyword


char[] charArray = {'H', 'e', 'l', 'l', 'o'};
String str2 = new String(charArray); // Using char array
System.out.println("String using char array: " + str2);

byte[] byteArray = {72, 101, 108, 108, 111}; // ASCII values for "Hello"
String str3 = new String(byteArray); // Using byte array
System.out.println("String using byte array: " + str3);

// Using a portion of char array


String str4 = new String(charArray, 0, 3); // Using portion of char array
System.out.println("String using portion of char array: " + str4);

// Using another string


String str5 = new String("Hello, World!"); // Using another string
System.out.println("String using another string: " + str5);

// Using StringBuffer
StringBuffer stringBuffer = new StringBuffer("Hello");
String str6 = new String(stringBuffer); // Using StringBuffer
System.out.println("String using StringBuffer: " + str6);
}
}
Output
String using string literal: Hello, World!
String using char array: Hello
String using byte array: Hello
String using portion of char array: Hel
String using another string: Hello, World!
String using StringBuffer: Hello
5.Implement a java program to illustrate the use of different types of character
extraction, string comparison, string search and string modification methods.

public class Main {


public static void main(String[] args) {
// Character extraction
String str = "Hello, World!";
char firstChar = str.charAt(0); // Extract the first character
char lastChar = str.charAt(str.length() - 1); // Extract the last character
System.out.println("First character: " + firstChar);
System.out.println("Last character: " + lastChar);

// Substring extraction
String substring = str.substring(7); // Extract substring from index 7 to end
System.out.println("Substring: " + substring);

// String comparison
String str1 = "hello";
String str2 = "HELLO";
boolean isEqualIgnoreCase = str1.equalsIgnoreCase(str2); // Compare ignoring case
System.out.println("Strings are equal ignoring case: " + isEqualIgnoreCase);

// String search
int indexOfComma = str.indexOf(','); // Find index of first occurrence of ','
System.out.println("Index of comma: " + indexOfComma);

// String modification
String modifiedStr = str.replace("Hello", "Hi"); // Replace "Hello" with "Hi"
System.out.println("Modified string: " + modifiedStr);

// String concatenation
String concatStr = str.concat(" How are you?"); // Concatenate another string
System.out.println("Concatenated string: " + concatStr);

// String trimming
String paddedStr = " Trim me ";
String trimmedStr = paddedStr.trim(); // Trim leading and trailing whitespace
System.out.println("Trimmed string: " + trimmedStr);

// String case conversion


String lowerCaseStr = str.toLowerCase(); // Convert to lower case
String upperCaseStr = str.toUpperCase(); // Convert to upper case
System.out.println("Lower case: " + lowerCaseStr);
System.out.println("Upper case: " + upperCaseStr);
}
}
Output
First character: H
Last character: !
Substring: World!
Strings are equal ignoring case: true
Index of comma: 5
Modified string: Hi, World!
Concatenated string: Hello, World! How are you?
Trimmed string: Trim me
Lower case: hello, world!
Upper case: HELLO, WORLD!
6. Implement a java program to illustrate the use of different types of StringBuffer
methods
public class Main {
public static void main(String[] args) {
// Create a StringBuffer object
StringBuffer stringBuffer = new StringBuffer("Hello");

// Append method
stringBuffer.append(", World!"); // Append a string
System.out.println("After append: " + stringBuffer);

// Insert method
stringBuffer.insert(5, " Java"); // Insert a string at index 5
System.out.println("After insert: " + stringBuffer);

// Delete method
stringBuffer.delete(5, 10); // Delete characters from index 5 to index 9
System.out.println("After delete: " + stringBuffer);

// Reverse method
stringBuffer.reverse(); // Reverse the string
System.out.println("After reverse: " + stringBuffer);

// Replace method
stringBuffer.replace(0, 5, "Hola"); // Replace characters from index 0 to index 4 with "Hola"
System.out.println("After replace: " + stringBuffer);

// Capacity and length methods


int capacity = stringBuffer.capacity(); // Get the current capacity
int length = stringBuffer.length(); // Get the current length
System.out.println("Capacity: " + capacity);
System.out.println("Length: " + length);
// Set length method
stringBuffer.setLength(5); // Set the length of the string to 5
System.out.println("After setting length: " + stringBuffer);
}
}
output
After append: Hello, World!
After insert: Hello Java, World!
After delete: Hello, World!
After reverse: !dlroW ,olleH
After replace: HolaW ,olleH
Capacity: 21
Length: 12
After setting length: HolaW
7.Demonstrate a swing event handling application that creates 2 buttons Alpha and
Beta and displays the text “Alpha pressed” when alpha button is clicked and “Beta
pressed” when beta button is clicked.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingEventHandlingExample {


public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

private static void createAndShowGUI() {


// Create and set up the window
JFrame frame = new JFrame("Button Event Handling Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Create the buttons


JButton alphaButton = new JButton("Alpha");
JButton betaButton = new JButton("Beta");

// Create the label to display the button press messages


JLabel label = new JLabel("Press a button");

// Create and register the event listeners


alphaButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText("Alpha pressed");
}
});

betaButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText("Beta pressed");
}
});

// Add the buttons and label to the content pane


Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(alphaButton);
contentPane.add(betaButton);
contentPane.add(label);

// Display the window


frame.pack();
frame.setVisible(true);
}
}
8.A program to display greeting message on the browser “Hello UserName”, “How Are You?”, accept
username from the client using servlet.

Step 1: HTML Form

Create an index.html file with the following content:

<!DOCTYPE html>
<html>
<head>
<title>Greeting Form</title>
</head>
<body>
<form action="GreetingServlet" method="post">
<label for="username">Enter your username:</label>
<input type="text" id="username" name="username">
<input type="submit" value="Submit">
</form>
</body>
</html>

Step 2: Servlet

Create a servlet class GreetingServlet.java:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/GreetingServlet")
public class GreetingServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
// Get the username from the request
String username = request.getParameter("username");

// Set the content type of the response


response.setContentType("text/html");

// Get the response writer


PrintWriter out = response.getWriter();

// Generate the response


out.println("<html>");
out.println("<head><title>Greeting</title></head>");
out.println("<body>");
out.println("<h1>Hello " + username + "</h1>");
out.println("<p>How Are You?</p>");
out.println("</body>");
out.println("</html>");
}
}

Step 3: Deployment Descriptor

Update the web.xml file (if not using annotations) to map the servlet:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<servlet>
<servlet-name>GreetingServlet</servlet-name>
<servlet-class>com.example.GreetingServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>GreetingServlet</servlet-name>
<url-pattern>/GreetingServlet</url-pattern>
</servlet-mapping>
</web-app>

Step 4: Compile and Run

1. Compile the servlet and deploy it to your servlet container (like Tomcat).
2. Place the HTML file in the appropriate directory, typically the webapps directory of your servlet container.
3. Start your servlet container and navigate to the index.html page in your web browser.
4. Enter a username and submit the form to see the greeting message.

This setup should work for a basic servlet application that greets the user by the provided username.

Output:
When you run the above program, the following sequence of actions and outputs will occur:

1. Access the HTML Form:


o Open a web browser.
o Navigate to the URL where your index.html is hosted, for example,
http://localhost:8080/YourWebApp/index.html.
2. HTML Form Display:
o The browser will display the form where you can enter your username:
<!DOCTYPE html>
<html>
<head>
<title>Greeting Form</title>
</head>
<body>
<form action="GreetingServlet" method="post">
<label for="username">Enter your username:</label>
<input type="text" id="username" name="username">
<input type="submit" value="Submit">
</form>
</body>
</html>

This will look like:


Enter your username: [__________] [Submit]

• Submit the Form:

• Enter a username, e.g., "Vishwas", in the input box.


• Click the "Submit" button.

• Servlet Processing:

• The form submits the data to the GreetingServlet.


• The GreetingServlet processes the request, retrieves the username from the request parameter,
and generates an HTML response.

• Generated HTML Response:

• The servlet generates an HTML response with the greeting message.


• The browser displays the generated response.

The resulting output in the browser will be:

<!DOCTYPE html>
<html>
<head>
<title>Greeting</title>
</head>
<body>
<h1>Hello Vishwas</h1>
<p>How Are You?</p>
</body>
</html>
``
9.A servlet program to display the name, USN, and total marks by accepting student
detail
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/StudentDetailsServlet")
public class StudentDetailsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
// Set content type of the response
response.setContentType("text/html");

// Get the PrintWriter object to write the HTML response


PrintWriter out = response.getWriter();

// Retrieve student details from the request


String name = request.getParameter("name");
String usn = request.getParameter("usn");
int totalMarks = Integer.parseInt(request.getParameter("totalMarks"));

// Display student details on the web page


out.println("<html>");
out.println("<head><title>Student Details</title></head>");
out.println("<body>");
out.println("<h1>Student Details</h1>");
out.println("<p>Name: " + name + "</p>");
out.println("<p>USN: " + usn + "</p>");
out.println("<p>Total Marks: " + totalMarks + "</p>");
out.println("</body>");
out.println("</html>");

// Close the PrintWriter


out.close();
}
}

<!DOCTYPE html>
<html>
<head>
<title>Student Details Form</title>
</head>
<body>
<h1>Enter Student Details</h1>
<form action="StudentDetailsServlet" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="usn">USN:</label>
<input type="text" id="usn" name="usn"><br><br>
<label for="totalMarks">Total Marks:</label>
<input type="number" id="totalMarks" name="totalMarks"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
10.A Java program to create and read the cookie for the given cookie name as
“EMPID” and its value as “AN2356”.

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;

@WebServlet("/CookieExampleServlet")
public class CookieExampleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
// Create a cookie with name "EMPID" and value "AN2356"
Cookie empIdCookie = new Cookie("EMPID", "AN2356");

// Add the cookie to the response


response.addCookie(empIdCookie);

response.setContentType("text/html");
response.getWriter().println("<html><body>");
response.getWriter().println("<h2>Cookie Created Successfully!</h2>");
response.getWriter().println("<p>Name: " + empIdCookie.getName() + "</p>");
response.getWriter().println("<p>Value: " + empIdCookie.getValue() + "</p>");
response.getWriter().println("</body></html>");
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
// Read the cookie with name "EMPID"
Cookie[] cookies = request.getCookies();
String empId = null;
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("EMPID")) {
empId = cookie.getValue();
break;
}
}
}

response.setContentType("text/html");
response.getWriter().println("<html><body>");
if (empId != null) {
response.getWriter().println("<h2>Cookie Found!</h2>");
response.getWriter().println("<p>Name: EMPID</p>");
response.getWriter().println("<p>Value: " + empId + "</p>");
} else {
response.getWriter().println("<h2>Cookie Not Found!</h2>");
}
response.getWriter().println("</body></html>");
}
}

11.Write a JAVA Program to insert data into Student DATA BASE and retrieve info
based on particular queries(For example update, delete, search etc.

import java.sql.*;

public class StudentDatabaseExample {


// JDBC URL, username, and password of MySQL server
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/studentdb";
private static final String USERNAME = "your_username";
private static final String PASSWORD = "your_password";

public static void main(String[] args) {


try {
// Connect to the database
Connection connection = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD);

// Create a statement
Statement statement = connection.createStatement();

// Create the Student table if it does not exist


String createTableSQL = "CREATE TABLE IF NOT EXISTS Student (id INT AUTO_INCREMENT
PRIMARY KEY, " +
"name VARCHAR(100), age INT)";
statement.executeUpdate(createTableSQL);

// Insert some sample data into the Student table


String insertDataSQL = "INSERT INTO Student (name, age) VALUES ('John', 20), ('Alice', 22), ('Bob', 21)";
statement.executeUpdate(insertDataSQL);

// Retrieve all students


System.out.println("All Students:");
String selectAllSQL = "SELECT * FROM Student";
ResultSet resultSet = statement.executeQuery(selectAllSQL);
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
}

// Update a student's age


String updateSQL = "UPDATE Student SET age = 23 WHERE name = 'John'";
statement.executeUpdate(updateSQL);
System.out.println("\nStudent 'John' age updated.");

// Retrieve updated info for 'John'


System.out.println("\nUpdated Student 'John':");
resultSet = statement.executeQuery("SELECT * FROM Student WHERE name = 'John'");
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
}
// Delete a student
String deleteSQL = "DELETE FROM Student WHERE name = 'Alice'";
statement.executeUpdate(deleteSQL);
System.out.println("\nStudent 'Alice' deleted.");

// Search for students with age greater than 20


System.out.println("\nStudents with age > 20:");
resultSet = statement.executeQuery("SELECT * FROM Student WHERE age > 20");
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
}

// Close the resources


resultSet.close();
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
12.A program to design the Login page and validating the USER_ID and PASSWORD using
JSP and DataBase.

1. Setup Database: Create a database table to store user credentials (USER_ID and PASSWORD).
2. JSP Login Page: Create a JSP page with a form for users to enter their credentials.
3. Servlet for Handling Login: Create a servlet to handle the form submission and validate the user
credentials against the database.
4. Database Connectivity: Establish a connection to the database from the servlet and query the
database to validate the user credentials.
5. Redirect User: Redirect the user to a welcome page if the credentials are valid, or display an error
message if the credentials are invalid.

1.Database Table (MySQL):

CREATE TABLE users (

id INT AUTO_INCREMENT PRIMARY KEY,

user_id VARCHAR(50) NOT NULL,

password VARCHAR(50) NOT NULL

);
2.JSP login Page(Login.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Page</title>
</head>
<body>
<h2>Login</h2>
<form action="LoginServlet" method="post">
User ID: <input type="text" name="userId"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>

3. Servlet for Handling Login (LoginServlet.java):


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class LoginServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
String userId = request.getParameter("userId");
String password = request.getParameter("password");

// Database connection parameters


String url = "jdbc:mysql://localhost:3306/your_database";
String dbUser = "your_username";
String dbPassword = "your_password";

try {
// Load MySQL JDBC driver
Class.forName("com.mysql.jdbc.Driver");
// Connect to the database
Connection conn = DriverManager.getConnection(url, dbUser, dbPassword);

// Prepare SQL statement


String sql = "SELECT * FROM users WHERE user_id=? AND password=?";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setString(1, userId);
statement.setString(2, password);

// Execute the query


ResultSet result = statement.executeQuery();

if (result.next()) {
// Valid credentials, redirect to welcome page
response.sendRedirect("welcome.jsp");
} else {
// Invalid credentials, show error message
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<script>alert('Invalid credentials!');</script>");
RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
rd.include(request, response);
}

// Close database connection


conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}

4. Welcome Page (welcome.jsp):


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome Page</title>
</head>
<body>
<h2>Welcome!</h2>
<p>You have successfully logged in.</p>
</body>
</html>
Ensure you have MySQL JDBC driver (mysql-connector-java-x.x.xx.jar) in your classpath.

This is a simple example for demonstration purposes. In a real-world scenario, you would need to enhance
security measures like hashing passwords, handling exceptions properly, and applying other best practices
for web application security.

You might also like