title: Validation not happening for custom login page in Spring security
body: <p>I am trying execute sample example for spring security using custom login page.The application is not throwing any error.From home.jsp, it is navigating into custom login page but even after entering correct user id and password it is going back to home.jsp instead of hello.jsp without showing any error.Requesting your help in identifying the error.</p>
  
  <p>hello.jsp</p>
  
  <pre><code>&lt;%@ taglib prefix="c" uri="/WEB-INF/tld/c.tld" %&gt;
  &lt;html&gt;
  &lt;body&gt;
      &lt;h3&gt;message : ${message}&lt;/h3&gt;
      &lt;h3&gt;User name : ${username}&lt;/h3&gt;
      &lt;a href = "&lt;c:url value="/j_spring_security_logout" /&gt;"&gt;LogOut&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>home.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h3&gt;Welcome to spring security&lt;/h3&gt;
      &lt;a href="welcome"&gt;&lt;b&gt;Click here to logon&lt;/b&gt;&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>login.jsp</p>
  
  <pre><code>&lt;%@ taglib prefix="c" uri="/WEB-INF/tld/c.tld"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login Page&lt;/title&gt;
  &lt;style&gt;
  .errorblock {
      color: #ff0000;
      background-color: #ffEEEE;
      border: 3px solid #ff0000;
      padding: 8px;
      margin: 16px;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body onload='document.f.j_username.focus();'&gt;
      &lt;h3&gt;Login with Username and Password (Custom Page)&lt;/h3&gt;
  
      &lt;c:if test="${SPRING_SECURITY_LAST_EXCEPTION !=null}"&gt;&lt;!-- ${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;
  
       &lt;form name='f' action="&lt;c:url value='j_spring_security_check' /&gt;"
          method='GET'&gt;
  
  
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;User:&lt;/td&gt;
                  &lt;td&gt;&lt;input type='text' name='j_username' value=''&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password:&lt;/td&gt;
                  &lt;td&gt;&lt;input type='password' name='j_password' /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan='2'&gt;&lt;input name="submit" type="submit"
                      value="submit" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan='2'&gt;&lt;input name="reset" type="reset" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;web-app xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" id="WebApp_ID"&gt;
  &lt;display-name&gt;Spring MVC&lt;/display-name&gt;
  
  &lt;servlet&gt;
  &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
  &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
   &lt;listener&gt;
  &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;context-param&gt;
  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
  &lt;param-value&gt;
          /WEB-INF/mvc-dispatcher-servlet.xml,/WEB-INF/spring-security.xml 
          &lt;/param-value&gt;
  &lt;/context-param&gt;
   &lt;filter&gt;
  &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
  &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
  &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
  &lt;url-pattern&gt;/*&lt;/url-pattern&gt; 
  &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>mvc-dispatcher-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;beans xsi:schemaLocation=" http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-4.3.xsd" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:context="http://www.springframework.org/schema/context"
    xmlns="http://www.springframework.org/schema/beans"&gt;
  &lt;context:component-scan base-package="test"/&gt;
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/pages/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
      &lt;property name="basenames"&gt;
          &lt;list&gt;
              &lt;value&gt;mymessages&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>LoginController.java</p>
  
  <pre><code>package test;
  
  import java.security.Principal;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  public class LoginController {
  
      @RequestMapping(value = "/welcome", method = RequestMethod.GET)
      public String printWelcome(ModelMap model,Principal principal) {
          System.out.println("*****Hello controller called***");
          String name = principal.getName();
          model.addAttribute("username", name);
          model.addAttribute("message","spring security custom form example");
          return "hello";
  
      }
  
      @RequestMapping(value = "/login", method = RequestMethod.GET)
      public String login(ModelMap model) {
  
          return "login";
      }   
  
  
      @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
      public String loginerror(ModelMap model) {
  
          model.addAttribute("error","true");
          return "login";
      }
  
      @RequestMapping(value = "/logout", method = RequestMethod.GET)
      public String logout(ModelMap model) {
  
          return "login";
      }
  
      @RequestMapping(value = "/*", method = RequestMethod.GET)
      public String home(ModelMap model) {
  
          return "home";
      }
  }
  </code></pre>
  
  <p>spring-security.xml</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security-4.2.xsd"&gt;
  
       &lt;!-- &lt;http auto-config="true"&gt;
          &lt;intercept-url pattern="/welcome*" access="hasRole('ROLE_USER')" /&gt;
          &lt;http-basic /&gt;
      &lt;/http&gt;  --&gt;
  
      &lt;!-- &lt;http&gt;
          &lt;intercept-url pattern="/welcome*" access="hasRole('ROLE_USER')"/&gt;
          &lt;form-login/&gt;
          &lt;logout logout-success-url="/home"/&gt;
      &lt;/http&gt; --&gt;
  
       &lt;http&gt;
          &lt;intercept-url pattern="/welcome*" access="hasRole('ROLE_USER')"/&gt;
          &lt;form-login login-page="/login" default-target-url="/welcome" authentication-failure-url ="/loginfailed" /&gt;
          &lt;logout logout-success-url="/logout"/&gt;
           &lt;csrf disabled="true"/&gt;
      &lt;/http&gt;
  
       &lt;authentication-manager&gt;
          &lt;authentication-provider&gt;
            &lt;user-service&gt;
              &lt;user name="rahul" password="123" authorities="ROLE_USER" /&gt;
            &lt;/user-service&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt; 
  
  &lt;/beans:beans&gt;
  </code></pre>