Phonebook Java Web Project using Servlet JSP || Advance Java Project Phonebook App
Phonebook Java Web Project using Servlet JSP || Advance Java Project Phonebook App

index.jsp
<%-- Document : index Created on : 28 Nov, 2021, 12:01:12 AM Author : Dell --%> <%@page import="com.entity.User"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Phone Book</title> <%@include file="header.jsp" %> <link href="style.css" rel="stylesheet" type="text/css"/> <style> .backimage{ /* background: url("image/phone2.jpg");*/ background: url("https://images.unsplash.com/photo-1423666639041-f56000c27a9a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1174&q=80"); width: 100%; height: 86vh; background-repeat: no-repeat; background-size: cover; } </style> </head> <body> <div class="container-fluid backimage text-center text-success "> <h1>Welcome to Phone Book App</h1> </div> <%@include file="footer.jsp" %> </body> </html>
header.jsp
<%@page import="com.entity.User"%> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <a class="navbar-brand" href="index.jsp"><i class="fas fa-phone-square"></i> Phone Book </a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="index.jsp"><i class="fas fa-home"></i> Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item active"> <a class="nav-link" href="AddContect.jsp"><i class="fas fa-plus-square"></i> Add Phone Number</a> </li> <li class="nav-item active"> <a class="nav-link" href="ViewContact.jsp"><i class="fas fa-eye"></i> View Contact</a> </li> </ul> <% User myuser = (User) session.getAttribute("user"); if (myuser == null) { %> <form class="form-inline my-2 my-lg-0"> <a href="login.jsp" class="btn btn-success "><i class="fas fa-user"></i> Login</a> <a href="register.jsp" class="btn btn-danger ml-2"><i class="fas fa-users"></i> Register</a> </form> <% } else { %> <form class="form-inline my-2 my-lg-0" > <button class="btn btn-success"><%= myuser.getName()%></button> <button type="button" class="btn btn-danger ml-2" data-toggle="modal" data-target="#exampleModalCenter">Logout</button> </form> <% } %> <!-- Button trigger modal --> <!--Logout Modal --> <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body text-center"> <h6 >Do you want to Logout</h6> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <form action="LogoutServlet" method="post"> <button type="submit" class="btn btn-primary mt-2">logout</button> </form> </div> <div class="modal-footer"> </div> </div> </div> </div> </div> </nav>
footer.jsp
<%-- Document : footer Created on : 28 Nov, 2021, 12:01:39 AM Author : Dell --%> <div class="container-fluid bg-primary"> <h5 class="tex-white text-center p-2 text-white">Devloped By projectforjob </h5> </div>
editcontact.jsp
<%-- Document : editcontact Created on : 28 Nov, 2021, 6:55:44 PM Author : Dell --%> <%@page import="com.entity.Contact"%> <%@page import="com.dao.ContactDAO"%> <%@page import="com.conn.DbConnect"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <%@include file="header.jsp" %> <% if (myuser == null) { session.setAttribute("inviled", "Login Please..."); response.sendRedirect("login.jsp"); } %> <div class="container-fluid"> <div class="row p-2"> <div class="col-md-6 offset-md-3"> <div class="card"> <div class="card-body"> <h4 class="text-center text-success">Add Contact Page</h4> <% String sucssMsg = (String) session.getAttribute("sucssMsg"); String errorMsg = (String) session.getAttribute("errorMsg"); if (sucssMsg != null) { %> <p class="text-success text-center"><%=sucssMsg%></p> <% session.removeAttribute("sucssMsg"); } if (errorMsg != null) { %> <p class="text-danger text-center"><%=errorMsg%></p> <% session.removeAttribute("errorMsg"); } %> <form action="UpdateServ" method="post"> <% int cid=Integer.parseInt(request.getParameter("cid")); ContactDAO dao = new ContactDAO(DbConnect.getConn()); Contact c = dao.getCcontactById(cid); %> <input type="hidden" value="<%=cid %>" name="cid"> <div class="form-group"> <label for="exampleInputEmail1">Enter Name</label> <input type="text" name="name" value="<%=c.getName()%>" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter Name"> </div> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" value="<%=c.getEmail()%>" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Phone Number</label> <input value="<%=c.getPhone()%>" type="number" name="number" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="form-group"> <label for="exampleInputPassword1">Enter a message</label> <textarea name="about" class="form-control" rows="3" placeholder="Enter a message"><%=c.getAbout() %></textarea> </div> <div class="text-center m-3"> <button type="submit" class="btn btn-primary">Update </button> </div> </form> </div> </div> </div> </div> </div> <div style="margin-top: 130px"> <%@include file="footer.jsp" %> </div> </body> </html>
ViewContact.jsp
<%-- Document : ViewContact Created on : 28 Nov, 2021, 1:10:56 AM Author : Dell --%> <%@page import="com.dao.ContactDAO"%> <%@page import="java.util.List"%> <%@page import="com.entity.Contact"%> <%@page import="com.conn.DbConnect"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <%@include file="header.jsp" %> <% if (myuser == null) { session.setAttribute("inviled", "Login Please..."); response.sendRedirect("login.jsp"); } %> <% String sucssMsg = (String) session.getAttribute("sucssMsg"); String Msg = (String) session.getAttribute("Msg"); String ErMsg = (String) session.getAttribute("ErMsg"); if (sucssMsg != null) { %> <div class="alert alert-success" role = "alert" > <%=sucssMsg %> </div > <% session.removeAttribute("sucssMsg"); } if (Msg != null) { %> <div class="alert alert-danger" role = "alert" > <%=Msg %> </div > <% session.removeAttribute("Msg"); } if (ErMsg != null) { %> <div class="alert alert-success" role = "alert" > <%=ErMsg %> </div > <% session.removeAttribute("ErMsg"); } %> <div class="container"> <div class="row p-4"> <% if (myuser != null) { ContactDAO dao = new ContactDAO(DbConnect.getConn()); List<Contact> contact = dao.getAllContact(myuser.getId()); for (Contact c : contact) { %> <div class="col-md-3"> <div class="card crd-ho"> <div class="card-body"> <h5>Name : <%=c.getName()%></h5> <p>Phone No: <%=c.getPhone()%></p> <p> Email: <%=c.getEmail()%></p> <p> About: <%=c.getAbout()%> </p> <div class="text-center"> <a href="editcontact.jsp?cid=<%= c.getId()%>" class="btn btn-success tex-white">Edit</a> <a href="DelateServ?cid=<%= c.getId()%>" class="btn btn-danger tex-white">Delete</a> </div> </div> </div> </div> <% } } %> </div> </div> <div style="margin-top: 130px"> <%@include file="footer.jsp" %> </div> </body> </html>
AddContect.jsp
<%-- Document : AddContect Created on : 28 Nov, 2021, 1:10:28 AM Author : Dell --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <%@include file="header.jsp" %> <% if (myuser == null) { session.setAttribute("inviled", "Login Please..."); response.sendRedirect("login.jsp"); } %> <div class="container-fluid"> <div class="row p-2"> <div class="col-md-6 offset-md-3"> <div class="card"> <div class="card-body"> <h4 class="text-center text-success">Add Contact Page</h4> <% String sucssMsg=(String) session.getAttribute("sucssMsg"); String errorMsg=(String) session.getAttribute("errorMsg"); if(sucssMsg !=null){ %> <p class="text-success text-center"><%=sucssMsg %></p> <% session.removeAttribute("sucssMsg"); } if (errorMsg != null){ %> <p class="text-danger text-center"><%=errorMsg %></p> <% session.removeAttribute("errorMsg"); } %> <form action="AddContact" method="post"> <% if(myuser !=null) { %> <input type="hidden" value="<%= myuser.getId() %>" name="uid"> <%} %> <div class="form-group"> <label for="exampleInputEmail1">Enter Name</label> <input type="text" name="name" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter Name"> </div> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Phone Number</label> <input type="number" name="number" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="form-group"> <label for="exampleInputPassword1">Enter a message</label> <textarea name="about" class="form-control" rows="3" placeholder="Enter a message"></textarea> </div> <div class="text-center m-3"> <button type="submit" class="btn btn-primary">Submit</button> </div> </form> </div> </div> </div> </div> </div> <div style="margin-top: 130px"> <%@include file="footer.jsp" %> </div> </body> </html>
login.jsp
<%-- Document : login Created on : 28 Nov, 2021, 12:01:51 AM Author : Dell --%> <%@page import="com.entity.User"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <%@include file="header.jsp"%> <div class="container-fluid"> <div class="row p-2"> <div class="col-md-6 offset-md-3"> <div class="card"> <div class="card-body"> <h4 class="text-center text-success">Login Page</h4> <% String inviled=(String)session.getAttribute("inviled"); if(inviled!=null){ %> <p class="text-danger text-center"><%= inviled %></p> <% session.removeAttribute("inviled"); } %> <% String logMsg=(String)session.getAttribute("logMsg"); if(logMsg!=null){ %> <p class="text-success text-center"><%= logMsg%></p> <% session.removeAttribute("logMsg"); } %> <form action="LoginServlet" method="post"> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" name="pass" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="text-center m-3"> <button type="submit" class="btn btn-primary">Submit</button> </div> </form> </div> </div> </div> </div> </div> <div style="margin-top: 130px"> <%@include file="footer.jsp" %> </div> </body> </html>
register.jsp
<%-- Document : register Created on : 28 Nov, 2021, 12:02:05 AM Author : Dell --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <%@include file="header.jsp"%> <div class="container-fluid"> <div class="row p-2"> <div class="col-md-6 offset-md-3"> <div class="card"> <div class="card-body"> <h4 class="text-center text-success">Registation Page</h4> <% String sucssMsg=(String) session.getAttribute("sucssMsg"); String errorMsg=(String) session.getAttribute("errorMsg"); if(sucssMsg !=null){ %> <p class="text-success text-center"><%=sucssMsg %></p> <% session.removeAttribute("sucssMsg"); } if (errorMsg != null){ %> <p class="text-danger text-center"><%=errorMsg %></p> <% session.removeAttribute("errorMsg"); } %> <form action="register" method="post"> <div class="form-group"> <label for="exampleInputEmail1">Enter Name</label> <input type="text" name="name" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter Name"> </div> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" name="pass" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="text-center m-3"> <button type="submit" class="btn btn-primary">Submit</button> </div> </form> </div> </div> </div> </div> </div> <div style="margin-top: 130px"> <%@include file="footer.jsp" %> </div> </body> </html>