github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/internal/browser/javaproject/src/main/com/shashi/servlets/UserRegServlet.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  
    19  @SuppressWarnings("serial")
    20  @WebServlet("/userreg")
    21  public class UserRegServlet extends HttpServlet {
    22  
    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  		try {
    29  			UserBean user = new UserBean();
    30  			user.setMailId(req.getParameter("mailid"));
    31  			user.setPWord(req.getParameter("pword"));
    32  			user.setFName(req.getParameter("firstname"));
    33  			user.setLName(req.getParameter("lastname"));
    34  			user.setAddr(req.getParameter("address"));
    35  			user.setPhNo(Long.parseLong(req.getParameter("phoneno")));
    36  
    37  			String message = userService.registerUser(user);
    38  			if ("SUCCESS".equalsIgnoreCase(message)) {
    39  				RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html");
    40  				rd.include(req, res);
    41  				pw.println("<div class='tab'><p1 class='menu'>User Registered Successfully !</p1></div>");
    42  
    43  			} else {
    44  				RequestDispatcher rd = req.getRequestDispatcher("UserRegister.html");
    45  				rd.include(req, res);
    46  				pw.println("<div class='tab'><p1 class='menu'>" + message + "</p1></div>");
    47  
    48  			}
    49  
    50  		} catch (Exception e) {
    51  			throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage());
    52  		}
    53  	}
    54  
    55  }