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

ansil

The document outlines a web application for user management, including HTML and JSP code for user registration, listing, updating, and deletion. It connects to a MySQL database to manage user data, with forms for input and navigation links for different functionalities. The application features a consistent dark theme with green accents for UI elements.

Uploaded by

mohammedansil791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ansil

The document outlines a web application for user management, including HTML and JSP code for user registration, listing, updating, and deletion. It connects to a MySQL database to manage user data, with forms for input and navigation links for different functionalities. The application features a consistent dark theme with green accents for UI elements.

Uploaded by

mohammedansil791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

ASSIGNMENT 2

WEB PAGE :
<!DOCTYPE html>

<html>

<head>

<style>

body {

background-color: #1e1e1e;

color: #f0f0f0;

font-family: Arial, sans-serif;

margin: 0;

.header {

background-color: #333;

text-align: center;

padding: 20px 0;

.header-title {

font-size: 40px;

color: #4caf50;

.nav {

background-color: #444;

.nav td {

padding: 10px;

.nav a {

text-decoration: none;

color: #4caf50;
padding: 8px 16px;

border-radius: 5px;

transition: background-color 0.3s;

.nav a:hover {

background-color: #4caf50;

color: #1e1e1e;

</style>

</head>

<body>

<table border="0" width="100%">

<tr>

<td>

<div class="header">

<span class="header-title">USER MANAGEMENT</span>

</div>

</td>

</tr>

<tr>

<td>

<table class="nav" border="0" width="100%" align="center">

<tr align="center">

<td><a href="web.jsp">HOME</a></td>

<td><a href="users.jsp">USER</a></td>

<td><a href="register.jsp">REGISTER</a></td>

</tr>

</table>

</td>

</tr>
</table>

</body>

</html>

REGISTRATION :

<%@ page import="java.sql.*" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>

<%

String jdbcUrl = "jdbc:mysql://localhost:3306/student";

String username = "root"; // Your database username

String password = "windows"; // Your database password

Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

try {
// Load the JDBC driver

Class.forName("com.mysql.cj.jdbc.Driver");

// Establish the connection

connection = DriverManager.getConnection(jdbcUrl, username, password);

// Create a statement

statement = connection.createStatement();

String id = request.getParameter("id");

String name = request.getParameter("name");

String email = request.getParameter("email");

if (id != null && name != null && email != null) {

String sql = "INSERT INTO users VALUES(" + id + ", '" + name + "', '" +
email + "')";

statement.executeUpdate(sql);

response.sendRedirect("users.jsp");

} catch (SQLException e) {

e.printStackTrace();

out.println("Database access error: " + e.getMessage());

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>User Management</title>

<style>

body {

background-color: #1e1e1e;

color: #f0f0f0;

font-family: Arial, sans-serif;


margin: 0;

.header {

background-color: #333;

text-align: center;

padding: 20px 0;

.header-title {

font-size: 40px;

color: #4caf50;

.nav {

background-color: #444;

.nav td {

padding: 10px;

.nav a {

text-decoration: none;

color: #4caf50;

padding: 8px 16px;

border-radius: 5px;

transition: background-color 0.3s;

.nav a:hover {

background-color: #4caf50;

color: #1e1e1e;

.form-container {

background-color: #333;

padding: 20px;
border-radius: 10px;

width: 50%;

margin: 20px auto;

.form-container h4 {

color: #4caf50;

.form-container input[type="text"] {

padding: 5px;

width: 100%;

margin-bottom: 10px;

border: 1px solid #4caf50;

border-radius: 5px;

background-color: #222;

color: #f0f0f0;

.form-container input[type="submit"] {

padding: 8px 16px;

background-color: #4caf50;

border: none;

border-radius: 5px;

color: #1e1e1e;

cursor: pointer;

transition: background-color 0.3s;

.form-container input[type="submit"]:hover {

background-color: #66bb6a;

</style>

</head>

<body>
<table border="0" width="100%">

<tr>

<td>

<div class="header">

<span class="header-title">USER MANAGEMENT</span>

</div>

</td>

</tr>

<tr>

<td>

<table class="nav" border="0" width="100%" align="center">

<tr align="center">

<td><a href="web.jsp">HOME</a></td>

<td><a href="users.jsp">USER</a></td>

<td><a href="register.jsp">REGISTER</a></td>

</tr>

</table>

</td>

</tr>

</table>

<center>

<div class="form-container">

<h4>Enter Form Details</h4>

<form action="" method="post">

<table border="0">

<tr>

<td><h4>Id:</h4></td>

<td><input type="text" name="id"></td>

</tr>
<tr>

<td><h4>Name:</h4></td>

<td><input type="text" name="name"></td>

</tr>

<tr>

<td><h4>Email:</h4></td>

<td><input type="text" name="email"></td>

</tr>

<tr>

<td colspan="2" align="center">

<input type="submit" value="Submit">

</td>

</tr>

</table>

</form>

</div>

</center>

</body>

</html>

USER :
<%@ page import="java.sql.*" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-


8">

<title>User List</title>

<style>

body {

background-color: #1e1e1e;

color: #f0f0f0;

font-family: Arial, sans-serif;

margin: 0;

.header {

background-color: #333;

text-align: center;

padding: 20px 0;

.header-title {

font-size: 40px;

color: #4caf50;

.nav {

background-color: #444;

.nav td {
padding: 10px;

.nav a {

text-decoration: none;

color: #4caf50;

padding: 8px 16px;

border-radius: 5px;

transition: background-color 0.3s;

.nav a:hover {

background-color: #4caf50;

color: #1e1e1e;

table {

border-collapse: collapse;

margin: 20px auto;

width: 80%;

table, th, td {

border: 1px solid #4caf50;

th, td {

padding: 10px;

text-align: center;

th {

background-color: #333;

color: #4caf50;

}
tr:nth-child(even) {

background-color: #2a2a2a;

tr:nth-child(odd) {

background-color: #1f1f1f;

.button-container {

text-align: center;

margin-top: 20px;

.button-container button {

padding: 8px 16px;

background-color: #4caf50;

border: none;

border-radius: 5px;

color: #1e1e1e;

cursor: pointer;

margin: 0 5px;

transition: background-color 0.3s;

.button-container button:hover {

background-color: #66bb6a;

.button-container a {

text-decoration: none;

color: #1e1e1e;

</style>

</head>
<body>

<table border="0" width="100%">

<tr>

<td>

<div class="header">

<span class="header-title">REGISTRATION</span>

</div>

</td>

</tr>

<tr>

<td>

<table class="nav" border="0" width="100%" align="center">

<tr align="center">

<td><a href="web.jsp">HOME</a></td>

<td><a href="users.jsp">USER</a></td>

<td><a href="register.jsp">REGISTER</a></td>

</tr>

</table>

</td>

</tr>

</table>

<center>

<h1 style="color: #4caf50;">User List</h1>

<%

String jdbcUrl = "jdbc:mysql://localhost:3306/student";

String username = "root";

String password = "windows";


Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

try {

Class.forName("com.mysql.cj.jdbc.Driver");

connection = DriverManager.getConnection(jdbcUrl, username,


password);

statement = connection.createStatement();

String sql = "SELECT * FROM users";

resultSet = statement.executeQuery(sql);

%>

<table>

<tr><th>ID</th><th>Name</th><th>Email</th></tr>

<%

while (resultSet.next()) {

%>

<tr>

<td><%= resultSet.getInt("id") %></td>

<td><%= resultSet.getString("name") %></td>

<td><%= resultSet.getString("email") %></td>

</tr>

<%

%>

</table>

<%

} catch (SQLException e) {

e.printStackTrace();

out.println("Database access error: " + e.getMessage());


}

%>

</center>

<div class="button-container">

<button type="button">Edit</button>

<button type="button"><a href="delete.jsp">Delete</a></button>

<button type="button"><a href="update.jsp">Update</a></button>

</div>

</body>

</html>

UPDATE :

<%@ page import="java.sql.*" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>

<%

String jdbcUrl = "jdbc:mysql://localhost:3306/student";

String username = "root";

String password = "windows";

Connection connection = null;


Statement statement = null;

ResultSet resultSet = null;

try {

Class.forName("com.mysql.cj.jdbc.Driver");

connection = DriverManager.getConnection(jdbcUrl, username, password);

statement = connection.createStatement();

String id = request.getParameter("id");

String name = request.getParameter("name");

String email = request.getParameter("email");

if (id != null && name != null && email != null) {

String sql = "UPDATE users SET name = '" + name + "', email = '" + email
+ "' WHERE id = " + id;

statement.executeUpdate(sql);

response.sendRedirect("users.jsp");

} catch (SQLException e) {

e.printStackTrace();

out.println("Database access error: " + e.getMessage());

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Update User</title>

<style>

body {

background-color: #1e1e1e;

color: #f0f0f0;

font-family: Arial, sans-serif;

margin: 0;
}

.header {

background-color: #333;

text-align: center;

padding: 20px 0;

.header-title {

font-size: 40px;

color: #4caf50;

.nav {

background-color: #444;

.nav td {

padding: 10px;

.nav a {

text-decoration: none;

color: #4caf50;

padding: 8px 16px;

border-radius: 5px;

transition: background-color 0.3s;

.nav a:hover {

background-color: #4caf50;

color: #1e1e1e;

table {

border-collapse: collapse;

margin: 20px auto;

width: 50%;
background-color: #2a2a2a;

border: 1px solid #4caf50;

th, td {

padding: 10px;

text-align: center;

th {

background-color: #333;

color: #4caf50;

tr:nth-child(even) {

background-color: #2a2a2a;

tr:nth-child(odd) {

background-color: #1f1f1f;

input[type="text"] {

padding: 5px;

border: 1px solid #4caf50;

border-radius: 5px;

background-color: #333;

color: #f0f0f0;

input[type="submit"] {

padding: 8px 16px;

background-color: #4caf50;

border: none;

border-radius: 5px;

color: #1e1e1e;

cursor: pointer;
transition: background-color 0.3s;

input[type="submit"]:hover {

background-color: #66bb6a;

</style>

</head>

<body>

<table border="0" width="100%">

<tr>

<td>

<div class="header">

<span class="header-title">USER MANAGEMENT</span>

</div>

</td>

</tr>

<tr>

<td>

<table class="nav" border="0" width="100%" align="center">

<tr align="center">

<td><a href="web.jsp">HOME</a></td>

<td><a href="users.jsp">USER</a></td>

<td><a href="register.jsp">REGISTER</a></td>

</tr>

</table>

</td>

</tr>

</table>

<center>
<h2 style="color: #4caf50;">Enter Form Details to Update</h2>

<form action="" method="post">

<table border="1">

<tr align="center">

<td><h4>Id:</h4></td>

<td><input type="text" name="id"></td>

</tr>

<tr align="center">

<td><h4>Name:</h4></td>

<td><input type="text" name="name"></td>

</tr>

<tr align="center">

<td><h4>Email:</h4></td>

<td><input type="text" name="email"></td>

</tr>

<tr align="center">

<td colspan="2">

<input type="submit" value="Update">

</td>

</tr>

</table>

</form>

</center>

</body>

</html>
DELETE :

<%@ page import="java.sql.*" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Delete User</title>

<style>

body {
background-color: #1e1e1e;

color: #f0f0f0;

font-family: Arial, sans-serif;

margin: 0;

.header {

background-color: #333;

text-align: center;

padding: 20px 0;

.header-title {

font-size: 40px;

color: #4caf50;

.nav {

background-color: #444;

.nav td {

padding: 10px;

.nav a {

text-decoration: none;

color: #4caf50;

padding: 8px 16px;

border-radius: 5px;

transition: background-color 0.3s;

.nav a:hover {

background-color: #4caf50;

color: #1e1e1e;

}
table {

border-collapse: collapse;

margin: 20px auto;

width: 50%;

background-color: #2a2a2a;

border: 1px solid #4caf50;

th, td {

padding: 10px;

text-align: center;

th {

background-color: #333;

color: #4caf50;

tr:nth-child(even) {

background-color: #2a2a2a;

tr:nth-child(odd) {

background-color: #1f1f1f;

input[type="text"] {

padding: 5px;

border: 1px solid #4caf50;

border-radius: 5px;

background-color: #333;

color: #f0f0f0;

button[type="submit"] {

padding: 8px 16px;

background-color: #4caf50;
border: none;

border-radius: 5px;

color: #1e1e1e;

cursor: pointer;

transition: background-color 0.3s;

button[type="submit"]:hover {

background-color: #66bb6a;

</style>

</head>

<body>

<table border="0" width="100%">

<tr>

<td>

<div class="header">

<span class="header-title">USER MANAGEMENT</span>

</div>

</td>

</tr>

<tr>

<td>

<table class="nav" border="0" width="100%" align="center">

<tr align="center">

<td><a href="web.jsp">HOME</a></td>

<td><a href="user.jsp">USER</a></td>

<td><a href="register.jsp">REGISTER</a></td>

</tr>

</table>

</td>
</tr>

</table>

<center>

<h2 style="color: #4caf50;">Delete User</h2>

<form action="" method="post">

<table border="1">

<tr align="center">

<td>Enter ID to be deleted:</td>

<td><input type="text" name="id"></td>

</tr>

<tr align="center">

<td colspan="2">

<button type="submit">Delete</button>

</td>

</tr>

</table>

</form>

</center>

<%

String jdbcUrl = "jdbc:mysql://localhost:3306/student";

String username = "root";

String password = "windows";

Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

String id = request.getParameter("id");

try {

if (id != null) {

Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(jdbcUrl, username,
password);

statement = connection.createStatement();

String sql = "DELETE FROM users WHERE id=" + id;

statement.executeUpdate(sql);

response.sendRedirect("users.jsp");

} catch (SQLException e) {

e.printStackTrace();

out.println("Database access error: " + e.getMessage());

%>

</body>

</html>

You might also like