Html form:
<form method="post" action="/login">
<input class="inputLogin" type="text" name="username" value="" placeholder="Email" >
<input class="inputPassword" type="password" name="password" value="" placeholder="Password">
<br>
<input class="formButton" type="submit" name="commit" value="Login">
</form>
Servlet:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter(USERNAME_PARAMETER);
String password = req.getParameter(PASSWORD_PARAMETER);
boolean authenticated = authService.authenticate(req.getSession(), username, password);
if (authenticated) {
resp.sendRedirect("/user/home-page");
} else {
System.out.println("ELSE");
req.setAttribute(ERR_ATTRIBUTE, "Invalid credentials!");
req.getRequestDispatcher("/login").forward(req, resp);
}
}
When I send form, I get a infinite recursion of calling this servlet and stackoverflow.
Where is a problem?