Spring Security: The localhost page isn’t working
<blockquote>
  <p>web.xml</p>
</blockquote>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;

    &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
    &lt;context-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;
            /WEB-INF/spring/root-context.xml
            /WEB-INF/spring/security-context.xml
        &lt;/param-value&gt;
    &lt;/context-param&gt;

    &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
    &lt;listener&gt;
        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;

    &lt;!-- Processes application requests --&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
            &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

&lt;!-- security config  --&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>

<blockquote>
  <p>security-context.xml</p>
</blockquote>

<ol>
<li><p>
    http://www.springframework.org/schema/beans/spring-beans.xsd
            <a href="http://www.springframework.org/schema/security" rel="nofollow">http://www.springframework.org/schema/security</a> <a href="http://www.springframework.org/schema/security/spring-security-4.0.xsd" rel="nofollow">http://www.springframework.org/schema/security/spring-security-4.0.xsd</a>"></p>

<pre><code>    &lt;security:http auto-config="true" use-expressions="false"&gt;
        &lt;security:form-login login-page="/login" login-processing-url="/login" username-parameter="uname" 
        password-parameter="pass" default-target-url="/home"/&gt;
        &lt;security:intercept-url pattern="/**" access="ROLE_USER"/&gt;
    &lt;/security:http&gt;

    &lt;security:authentication-manager&gt;
        &lt;security:authentication-provider&gt;
            &lt;security:user-service&gt;
                &lt;security:user name="spider" password="peter" authorities="ROLE_USER"/&gt;
                &lt;security:user name="ironman" password="tony" authorities="ROLE_ADMIN,ROLE_USER"/&gt;
                &lt;security:user name="thor" password="thor" authorities="ROLE_USER"/&gt;
            &lt;/security:user-service&gt;
        &lt;/security:authentication-provider&gt;
    &lt;/security:authentication-manager&gt;
&lt;/beans&gt;
</code></pre></li>
</ol>

<p>login.jsp</p>

<pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%&gt;
&lt;%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %&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;login&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form method="POST"&gt;
        Name:&lt;input type="text" name="uname"&gt;&lt;br&gt;
        Pass:&lt;input type="password" name="pass"&gt;&lt;br&gt;
        &lt;sec:csrfInput/&gt;
        &lt;input type="submit" value="Login"&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<blockquote>
  <p>HomeController.java</p>
</blockquote>

<pre><code>@Controller
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        logger.info("Welcome home! The client locale is {}.", locale);

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

        String formattedDate = dateFormat.format(date);

        model.addAttribute("serverTime", formattedDate );

        return "home";
    }

    @RequestMapping(value="/login",method=RequestMethod.GET)
    public String goLogin(){
        return "login";
    }

}
</code></pre>

<p>**> **url is "localhost:8080/controller/login"****</p>

<p><strong>and I got The localhost page isn’t working
localhost redirected you too many times.
ERR_TOO_MANY_REDIRECTS</strong></p>