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

Javascript

The document outlines a web application for user management using JSP and MySQL, including functionalities for user registration, listing, updating, and deleting users. It contains HTML structures for the web pages and Java code for database interactions. The application allows users to input their details and manage user records through a simple interface.

Uploaded by

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

Javascript

The document outlines a web application for user management using JSP and MySQL, including functionalities for user registration, listing, updating, and deleting users. It contains HTML structures for the web pages and Java code for database interactions. The application allows users to input their details and manage user records through a simple interface.

Uploaded by

mohammedansil791
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

ASSIGNMENT 2

WEB PAGE :
<html>

<head>

</head>

<body style="background-color:lightgray">

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

<tr>

<td height="100">

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

<tr style="background-color: yellow">

<td width="85%" align="center" style="font-size: 40px;color:


blue">USER MANAGEMENT</td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

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

<tr align="center" style="background-color:yellow">

<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>JSP Page</title>

</head>

<body style="background-color:lightgray">
<table border="0" width="100%">

<tr>

<td height="100">

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

<tr style="background-color: yellow">

<td width="85%" align="center" style="font-size: 40px;color:


blue"> USER MANAGEMENT </td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

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

<tr align="center" style="background-color:yellow">

<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>

<h4>Enter form Details</h4>

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

<table>

<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>

<input type="submit">

</td>

</tr>

</table>

</form>

</center>
</body>

</html>

USER :

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

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

language="java" %>

<html>

<head>

<title>User List</title>

</head>

<center>

<body style="background-color:lightgray">

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

<tr>

<td height="100">

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


<tr style="background-color: yellow">

<td width="85%" align="center" style="font-size:


40px;color: blue">REGISTRATION</td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

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

<tr align="center" style="background-color:yellow">

<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>

<h1>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);

out.println("<table border='1'>");

out.println("<tr><th>ID</th><th>Name</th><th>Email</th></tr>");

while (resultSet.next()) {

out.println("<tr>");

out.println("<td>" + resultSet.getInt("id") + "</td>");

out.println("<td>" + resultSet.getString("name") +"</td>");

out.println("<td>" + resultSet.getString("email") +"</td>");

out.println("</tr>");

out.println("</table>");

catch (SQLException e) {

e.printStackTrace();

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

%>

<tr>

<td>

</td>

</tr>

<tr>

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

</td>

<td>

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

</td>

<td>

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

</td>

</tr>

</body>

</center>

</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"; // 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 = "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>JSP Page</title>

</head>

<body style="background-color:lightgray">

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

<tr>

<td height="100">

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

<tr style="background-color: yellow">

<td width="85%" align="center" style="font-size: 40px;color:


blue"> USER MANAGEMENT </td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

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

<tr align="center" style="background-color:yellow">

<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>

</br>

</br>
</br>

</br>

</br>

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

<table align="center" border="3">

<tr align="center">

<td colspan="2">

<h4>Enter form Details To Update</h4>

</td>

</tr>

<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">

</td>

</tr>

</table>

</form>

</center>

</body>

</html>
DELETE :

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

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

language="java" %>

<html>

<head>

</head>

<body style="background-color:lightgray">

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

<tr>

<td height="100">

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

<tr style="background-color: yellow">

<td width="85%" align="center" style="font-size: 40px;color:


blue"> USER MANAGEMENT </td>

</tr>

</table>
</td>

</tr>

<tr>

<td>

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

<tr align="center" style="background-color:yellow">

<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>

<tr align="center">

<td>

<form action="">

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

</table>

</br>

</br>

</br>

<table>

<tr>

<td>

Enter ID to be deleted

</td>

<td>:</td>

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


</tr>

</table>

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

</form>

</td>

</tr>

</table>

<%

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