title: Spring Security error in displaying custom page
body: <p>I am working on Spring Security Integration,
  My application with inbuilt security page works fine.
  But for custom login page its giving error</p>
  
  <pre><code>The localhost page isn’t working
  </code></pre>
  
  <p>Here is my code for reference</p>
  
  <p>inside spring-security.xml</p>
  
  <pre><code>  &lt;http use-expressions="true"&gt;
        &gt;
  
          &lt;intercept-url pattern="/**" access="isAuthenticated()"/&gt; &lt;!-- this means all URL in this app will be checked if user is authenticated --&gt;
  
              &lt;form-login
              login-page="/login"
              default-target-url="/"
              authentication-failure-url="/login?error"
              username-parameter="username"
              password-parameter="password" /&gt;
  
  
          &lt;logout logout-url="/logout" logout-success-url="/"/&gt; &lt;!-- the logout url we will use in JSP --&gt;
      &lt;/http&gt;
  </code></pre>
  
  <p>In login.jsp</p>
  
  <pre><code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Custom Login Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body onload='document.loginForm.j_username.focus();'&gt;
  &lt;h3&gt;Custom Login Page&lt;/h3&gt;
  
  &lt;%
  
  String errorString = (String)request.getAttribute("error");
  if(errorString != null &amp;&amp; errorString.trim().equals("true")){
  out.println("Incorrect login name or password. Please retry using correct login name and password.");
  }
  %&gt;
  
  &lt;form name='loginForm' action="&lt;c:url value='j_spring_security_check' /&gt;"
  method='POST'&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&gt;&lt;input name="submit" type="submit"
  value="submit" /&gt;
  &lt;/td&gt;
  &lt;td&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>In controller:</p>
  
  <pre><code>@RequestMapping(value = "/login", method = RequestMethod.GET)
      public ModelAndView login(ModelMap mode,
              @RequestParam(value = "error", required = false) String error,
              @RequestParam(value = "logout", required = false) String logout) {
          System.out.println("\n\t -------------");
          ModelAndView model = new ModelAndView("login");
  
          if (error != null) {
              model.addObject("error", "Invalid username and password!");
          }
  
          if (logout != null) {
              model.addObject("msg", "You've been logged out successfully.");
          }
          return model;
  
      }
  </code></pre>
  
  <hr>
  
  <p>When I run project using in built form pulgin, the url is </p>
  
  <pre><code>http://localhost:8080/SpringMvcSecurity/spring_security_login
  </code></pre>
  
  <p>and after login if I manually hit the url</p>
  
  <pre><code>http://localhost:8080/SpringMvcSecurity/login
  </code></pre>
  
  <p>It shows me the login page
  But I don't if the page displays this time then why it is not displaying in custom configuration.
  Please help.</p>
  
  <p>Thanks shazin
  there are 4 changes</p>
  
  <blockquote>
    <ol>
    <li>Need to change the url name in RequestMapping url for ex:customlogin</li>
    <li>same name need to replace in spring-security.xml</li>
    <li>add line in spring-security.xml </li>
    <li>replace the username password attribute names, the way those appears in jsp page.</li>
    </ol>
  </blockquote>
  
  <p><code>&lt;intercept-url pattern="/customlogin" access="permitAll" /&gt;</code></p>