title: Display error login message on custom spring boot login form
body: <p>I'm working on a custom spring boot login form. When user provides wrong credentials, I want my application redirect to the same page and show an error. What I tried, is to create my own <code>failureHandler</code> and there in <code>onAuthenticationFailure</code> pass a parameter to a request. Then in my login .jsp form check if this parameter exists and based on it show an error, but it doesn't work. What am I doing wrong?</p>
  
  <pre><code>@Override
  protected void configure(HttpSecurity http) throws Exception {
      http
          .csrf()
              .disable()
          .authorizeRequests()
              .antMatchers("/admin/**")
                  .hasRole("ADMIN")
              .antMatchers("/user/**")
                  .hasAnyRole("USER", "ADMIN")
              .antMatchers("/guest*")
                  .permitAll()
              .anyRequest().authenticated()
              .and()
          .formLogin()
              .loginPage("/guest/login")
              .permitAll()
              .defaultSuccessUrl("/user/all-tasks", true)
              .failureUrl("/guest/login")
              .failureHandler(new MyAuthenticationFailureHandler())
              .and()
          .logout()
              .logoutUrl("/user/logout")
              .deleteCookies("JSESSIONID");
  }
  </code></pre>
  
  <pre><code>@Component
  public class MyAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
      @Override
      public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
          super.onAuthenticationFailure(request, response, exception);
          request.setAttribute("error", true);
      }
  }
  </code></pre>
  
  <pre><code>@Controller
  @RequestMapping("/guest")
  public class GuestController {
      @GetMapping("/login")
      public String login(){
          return "login";
      }
  }
  </code></pre>
  
  <pre><code>&lt;div&gt;
      &lt;c:if test="${error == true}"&gt;
          &lt;h1&gt;DUPA&lt;/h1&gt;
      &lt;/c:if&gt;
  &lt;/div&gt;
  </code></pre>