Advertisement
Guest User

Untitled

a guest
Mar 5th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. package manageuser.controllers;
  2.  
  3. import java.io.IOException;
  4. import java.security.NoSuchAlgorithmException;
  5. import java.util.ArrayList;
  6.  
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import javax.servlet.http.HttpSession;
  12.  
  13. import manageuser.properties.ConfigProperties;
  14. import manageuser.validates.ValidateUser;
  15.  
  16. /**
  17. * Servlet implementation class LoginController
  18. */
  19. public class LoginController extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21. private static final String USERNAME_PAR = "loginId";
  22. private static final String PASSWORD_PAR = "password";
  23.  
  24. /**
  25. * @see HttpServlet#HttpServlet()
  26. */
  27. public LoginController() {
  28. super();
  29. // TODO Auto-generated constructor stub
  30. }
  31.  
  32. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  33. throws ServletException, IOException {
  34. response.sendRedirect("ADM001");
  35. }
  36.  
  37. /**
  38. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  39. * response)
  40. */
  41. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  42. throws ServletException, IOException {
  43. // lấy thông tin từ form
  44. String username = request.getParameter(USERNAME_PAR);
  45. String password = request.getParameter(PASSWORD_PAR);
  46. // khởi tạo đối tượng validate
  47. ValidateUser validate = new ValidateUser();
  48. // Lấy các thông báo lỗi
  49. ArrayList<String> listMess;
  50. try {
  51. listMess = validate.validateLoginData(username, password);
  52. if (listMess.size() == 0) {
  53. HttpSession session = request.getSession();
  54. session.setAttribute("username", username);
  55. response.sendRedirect("ListUserController");
  56. } else {// Nếu có lỗi quay lại màn hình login kèm theo thông báo lỗi
  57. request.setAttribute("listMess", listMess);
  58. request.getRequestDispatcher("ADM001").forward(request, response);
  59. }
  60. } catch (NoSuchAlgorithmException e) {
  61. // chuyển hướng sang màn hình thông báo lối
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. } catch (IOException e) {
  65. // chuyển hướng sang màn hình thông báo lỗi
  66. }
  67. // Nếu không có lỗi
  68.  
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement