@Test public void wrongPasswordShouldRedirectToErrorPage() throws Exception { request.addParameter("j_username", VALID_USERNAME); request.addParameter("j_password", "wrongpassword"); servlet.service(request, response); assertUserEndedUpOnPage("/invalidlogin"); }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("j_username"); String pass = request.getParameter("j_password"); if (getAuthenticator().isValidLogin(user, pass)) { request.getSession().setAttribute("username", user); response.sendRedirect("/frontpage"); } else { forwardTo("/invalidlogin", request, response); } }
LoginServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("j_username"); String pass = request.getParameter("j_password"); if (getAuthenticator().isValidLogin(user, pass)) { request.getSession().setAttribute("username", user); response.sendRedirect("/frontpage"); } else { forwardTo("/invalidlogin", request, response); } } }
LoginServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("j_username"); String pass = request.getParameter("j_password"); if (getAuthenticator().isValidLogin(user, pass)) { request.getSession().setAttribute("username", user); response.sendRedirect("/frontpage"); } else { forwardTo("/invalidlogin", request, response); } }  }
LoginServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("j_username"); String pass = request.getParameter("j_password"); if (getAuthenticator().isValidLogin(user, pass)) { request.getSession().setAttribute("username", user); response.sendRedirect("/frontpage"); } else { forwardTo("/invalidlogin", request, response); } }   }
LoginServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("j_username"); String pass = request.getParameter("j_password"); if (getAuthenticator().isValidLogin(user, pass)) { request.getSession().setAttribute("username", user); response.sendRedirect("/frontpage"); } else { forwardTo("/invalidlogin", request, response); } }    }