title: Spring security custom error messages not showing
body: <p>I was using a tutorial on this link:</p>
  
  <blockquote>
    <p><a href="http://www.mkyong.com/spring-security/display-custom-error-message-in-spring-security/" rel="nofollow noreferrer">http://www.mkyong.com/spring-security/display-custom-error-message-in-spring-security/</a></p>
  </blockquote>
  
  <p>To show a custom error message on login form and I got it at the beginning. But after declaring a <strong>authentication-failure-handler-ref="myAuthErrorHandler"</strong>  for a custom failure authenticator handler I can't see it the custom message on the login form:</p>
  
  <p><img src="https://i.stack.imgur.com/tq2gD.jpg" alt="enter image description here"></p>
  
  <p>What I am doing wrong? Can anybody explain me what happen and why the '<strong>Invalid username or password</strong>' doesn't show?</p>
  
  <p>Here's the code:</p>
  
  <p><strong>AuthentificationListener</strong></p>
  
  <pre><code>public class AuthentificationListener implements AuthenticationFailureHandler {
  
  @Override
  public void onAuthenticationFailure(HttpServletRequest request,
          HttpServletResponse response, AuthenticationException ae)
          throws IOException, ServletException {
  
      UsernamePasswordAuthenticationToken user = (UsernamePasswordAuthenticationToken) ae
              .getAuthentication();
  
  
      /* User */
  
  
      response.sendRedirect(request.getContextPath()
              + "/abc/main/loginfailed");
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>applicationContext.xml:</strong></p>
  
  <pre><code>    &lt;bean id="myAuthErrorHandler" class="org.abc.handler.AuthentificationListener"/&gt;
  </code></pre>
  
  <p><strong>Spring Security:</strong></p>
  
  <pre><code>    &lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/abc/main/welcome*" access="ROLE_USER" /&gt;
      &lt;intercept-url pattern="/abc/main/record/**" access="ROLE_USER" /&gt;
  
      &lt;form-login 
  
      login-page="/abc/main/login" 
  
      authentication-failure-handler-ref="myAuthErrorHandler" 
  
      default-target-url="/abc/main/welcome"
  
      /&gt;
  
  
      &lt;logout logout-success-url="/abc/main/logout" /&gt;
  
  &lt;/http&gt;
  </code></pre>
  
  <p><strong>login.jsp:</strong></p>
  
  <pre><code>        &lt;c:if test="${not empty error}"&gt;
          &lt;div class="errorblock"&gt;
              Your login attempt was not successful, try again.&lt;br /&gt; Caused :
              ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
          &lt;/div&gt;
  
      &lt;/c:if&gt;
  </code></pre>
  
  <p><strong>LoginController.java:</strong></p>
  
  <pre><code>    @RequestMapping(value="/loginfailed", method = RequestMethod.GET)
  public String loginerror(ModelMap model) {
  
      model.addAttribute("error", "true");
      return "login";
  
  }
  </code></pre>
  
  <p><strong>Update:</strong> To answer on Mani answer, I'm using a <strong>LoginController</strong>, which redirects <strong>loginfailed</strong> requests to <strong>login.jsp</strong> and is sending an '<em>error</em>' attribute with the '<em>true</em>' value. The problem is I can't see the message on the <em>login.jsp</em> using this expression:</p>
  
  <pre><code>${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
  </code></pre>
  
  <p><strong>Any Idea? Thank You very much!</strong></p>