Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public class BankManagerLoginServlet extends HttpServlet {
  2. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  3. try {
  4. // Get username and password from login page request
  5. String username = request.getParameter("username");
  6. String password = request.getParameter("password");
  7. // Authenticate user
  8.  
  9. BankManager bankMgr = new BankManager();
  10. boolean isAuthentic = bankMgr.authenticateUser(username, password);
  11. // If user is authenticated then go to successful login page
  12.  
  13. if (isAuthentic) {
  14. request.setAttribute("login", new String("Login Successful."));
  15. getServletContext().getRequestDispatcher("/BankManagerServiceLoggedIn.jsp"). forward(request, response);
  16.  
  17. }
  18. else {
  19. // Otherwise, raise failed login exception and output unsuccessful login message to error page
  20. throw new FailedLoginException("Failed Login for user " + username + " with password " + password);
  21.  
  22. }
  23.  
  24. } catch (FailedLoginException ex) {
  25. // output failed login message to error page
  26. request.setAttribute("error", new String("Login Error"));
  27. request.setAttribute("message", ex.getMessage());
  28. getServletContext().getRequestDispatcher("/ErrorPage.jsp").forward(request, response);
  29.  
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement