github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/internal/browser/javaproject/src/main/com/shashi/servlets/UpdateUserProfile.java (about)

     1  package com.shashi.servlets;
     2  
     3  import java.io.IOException;
     4  import java.io.PrintWriter;
     5  
     6  import javax.servlet.RequestDispatcher;
     7  import javax.servlet.ServletException;
     8  import javax.servlet.annotation.WebServlet;
     9  import javax.servlet.http.HttpServlet;
    10  import javax.servlet.http.HttpServletRequest;
    11  import javax.servlet.http.HttpServletResponse;
    12  
    13  import com.shashi.beans.TrainException;
    14  import com.shashi.beans.UserBean;
    15  import com.shashi.constant.UserRole;
    16  import com.shashi.service.UserService;
    17  import com.shashi.service.impl.UserServiceImpl;
    18  import com.shashi.utility.TrainUtil;
    19  
    20  @SuppressWarnings("serial")
    21  @WebServlet("/updateuserprofile")
    22  public class UpdateUserProfile extends HttpServlet {
    23  	private UserService userService = new UserServiceImpl(UserRole.CUSTOMER);
    24  
    25  	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    26  		res.setContentType("text/html");
    27  		PrintWriter pw = res.getWriter();
    28  
    29  		TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER);
    30  
    31  		UserBean ub = TrainUtil.getCurrentCustomer(req);
    32  
    33  		String fName = req.getParameter("firstname");
    34  		String lName = req.getParameter("lastname");
    35  		String addR = req.getParameter("address");
    36  		long phNo = Long.parseLong(req.getParameter("phone"));
    37  		String mailId = req.getParameter("mail");
    38  
    39  		ub.setFName(fName);
    40  		ub.setLName(lName);
    41  		ub.setAddr(addR);
    42  		ub.setPhNo(phNo);
    43  		ub.setMailId(mailId);
    44  
    45  		try {
    46  			String message = userService.updateUser(ub);
    47  			if ("SUCCESS".equalsIgnoreCase(message)) {
    48  
    49  				RequestDispatcher rd = req.getRequestDispatcher("UserHome.html");
    50  				rd.include(req, res);
    51  				pw.println("<div class='tab'>" + "		<p1 class='menu'>" + "	Hello " + ub.getFName()
    52  						+ " ! Welcome to our new NITRTC Website" + "		</p1>" + "	</div>");
    53  				pw.println("<div class='main'><p1 class='menu'><a href='viewuserprofile'>view Profile</a></p1>"
    54  						+ "<p1 class='menu'><a href='edituserprofile'>Edit Profile</a></p1>"
    55  						+ "<p1 class='menu'><a href='changeuserpassword'>Change Password</a></p1>" + "</div>");
    56  				pw.println("<div class='tab'>Your Profile has Been Successfully Updated</div>");
    57  			} else {
    58  				RequestDispatcher rd = req.getRequestDispatcher("UserHome.html");
    59  				rd.include(req, res);
    60  				pw.println("<div class='main'><p1 class='menu'><a href='viewuserprofile'>view Profile</a></p1>"
    61  						+ "<p1 class='menu'><a href='edituserprofile'>Edit Profile</a></p1>"
    62  						+ "<p1 class='menu'><a href='changeuserpassword'>Change Password</a></p1>" + "</div>");
    63  				pw.println("<div class='tab'>Please Enter the valid Information</div>");
    64  			}
    65  		} catch (Exception e) {
    66  			throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage());
    67  
    68  		}
    69  
    70  	}
    71  
    72  }