Пример #1
0
 @Override
 public void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws IOException, ServletException {
   if (CookieUtils.getCookie(req, "name") == null) {
     req.getRequestDispatcher("/login.jsp").forward(req, resp);
   } else {
     resp.sendRedirect("/analyze");
   }
 }
Пример #2
0
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
    String name = req.getParameter("name");
    String password = req.getParameter("password");

    if (UserRepo.contains(name, password)) {
      CookieUtils.setCookie(resp, "name", name);
      resp.sendRedirect("/analyze");
    } else {
      req.setAttribute("message", "Username or password wrong.");
      req.getRequestDispatcher("/login.jsp").forward(req, resp);
    }
  }