Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package manageuser.controllers;
- import java.io.IOException;
- import java.security.NoSuchAlgorithmException;
- import java.util.ArrayList;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import manageuser.properties.ConfigProperties;
- import manageuser.validates.ValidateUser;
- /**
- * Servlet implementation class LoginController
- */
- public class LoginController extends HttpServlet {
- private static final long serialVersionUID = 1L;
- private static final String USERNAME_PAR = "loginId";
- private static final String PASSWORD_PAR = "password";
- /**
- * @see HttpServlet#HttpServlet()
- */
- public LoginController() {
- super();
- // TODO Auto-generated constructor stub
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.sendRedirect("ADM001");
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
- * response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // lấy thông tin từ form
- String username = request.getParameter(USERNAME_PAR);
- String password = request.getParameter(PASSWORD_PAR);
- // khởi tạo đối tượng validate
- ValidateUser validate = new ValidateUser();
- // Lấy các thông báo lỗi
- ArrayList<String> listMess;
- try {
- listMess = validate.validateLoginData(username, password);
- if (listMess.size() == 0) {
- HttpSession session = request.getSession();
- session.setAttribute("username", username);
- response.sendRedirect("ListUserController");
- } else {// Nếu có lỗi quay lại màn hình login kèm theo thông báo lỗi
- request.setAttribute("listMess", listMess);
- request.getRequestDispatcher("ADM001").forward(request, response);
- }
- } catch (NoSuchAlgorithmException e) {
- // chuyển hướng sang màn hình thông báo lối
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // chuyển hướng sang màn hình thông báo lỗi
- }
- // Nếu không có lỗi
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement