0% found this document useful (0 votes)
64 views4 pages

Edit User Profile Page

The document consists of a JSP page for editing user profiles and a corresponding servlet for updating user information. The JSP page checks if a user is logged in, displays a form for editing their profile, and handles success messages. The servlet processes the form submission, updates the user details in the session, and redirects back to the edit profile page with a success or failure message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views4 pages

Edit User Profile Page

The document consists of a JSP page for editing user profiles and a corresponding servlet for updating user information. The JSP page checks if a user is logged in, displays a form for editing their profile, and handles success messages. The servlet processes the form submission, updates the user details in the session, and redirects back to the edit profile page with a success or failure message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

edit_profile.

jsp

<%--
Document : edit_profile
Created on : 7 Jun 2024, [Link] am
Author : mbbin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@ taglib prefix="c" uri="[Link]
<%@page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<%@include file="all_component/all_css.jsp"%>
</head>
<body style="background-color: #f7f7f7;">
<c:if test="${empty userobj }">
<c:redirect url="[Link]" />
</c:if>
<%@include file="all_component/[Link]"%>
<div class="continer-fluid">
<div class="row p-4">
<div class="col-md-4 offset-md-4">
<div class="card">
<div class="card-body">
<div class="text-center">
<i class="fa fa-user-plus fa-2x"
aria-hidden="true"></i>

<c:if test="${not empty succMsg}">


<div class="alert alert-success" role="alert">$
{succMsg}</div>
<c:remove var="succMsg"/>
</c:if>

<h5>Edit Profile</h5>
</div>

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

<input type="hidden" name="id" value="${[Link] }">

<div class="form-group">
<label>Enter Full Name</label> <input type="text"

required="required" class="form-control"

id="exampleInputEmail1" aria-describedby="emailHelp"
name="name"
value="${[Link] }">
</div>

<div class="form-group">
<label>Enter Qualification</label> <input
type="text"
required="required" class="form-control"

id="exampleInputEmail1" aria-describedby="emailHelp" name="qua"


value="$
{[Link] }">
</div>
<div class="form-group">
<label>Enter Email</label> <input type="email"

required="required" class="form-control"

id="exampleInputEmail1" aria-describedby="emailHelp"
name="email"
value="${[Link] }">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Enter
Password</label> <input
required="required" type="password"
class="form-control"
id="exampleInputPassword1" name="ps"
value="${[Link] }">
</div>

<button type="submit"
class="btn btn-primary badge-pill btn-
block">Update</button>
</form>
</div>
</div>
</div>
</div>
</div>
<div style="margin-top: 50px;">
<%@include file="all_component/[Link]"%>
</div>
</html>

[Link]
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/[Link] to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/[Link] to edit
this template
*/
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
*
* @author mbbin
*/
@WebServlet("/update_profile")
public class UpdateUserServlet extends HttpServlet {

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
try (PrintWriter out = [Link]()) {
String name = [Link]("name");
String qualification = [Link]("qua");
String email = [Link]("email");
String password = [Link]("ps");

// Retrieve existing user from session


HttpSession session = [Link]();
User user = (User) [Link]("user");

// Update user details if user is found in session


if (user != null) {
[Link](name);
[Link](qualification);
[Link](email);
[Link](password);

UserDAO userDAO = new UserDAO([Link]());


boolean isUpdated = [Link](user);

if (isUpdated) {
[Link]("succMsg", "Profile Updated
Successfully!!");
} else {
[Link]("succMsg", "Failed to update profile!!");
}
} else {
[Link]("succMsg", "User not found in session");
}
[Link]("edit_profile.jsp");
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on


the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

You might also like