title: Spring Security Login error Status 404 - /j_spring_security_check
body: <p>This is the code for login system in Spring web mvc using spring security in eclipse.</p>
  
  <p>web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              WEB-INF/springsecurity-servlet.xml,
              WEB-INF/spring-sec.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&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;servlet&gt;
          &lt;servlet-name&gt;springsecurity&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;springsecurity&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;redirect.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>springsecurity-servlet.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      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.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security.xsd"
      xmlns:mvc="http://www.springframework.org/schema/mvc"&gt;
  
  
      &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="SpringSecurity" /&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
          &lt;property name="mappings"&gt;
              &lt;props&gt;
                  &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:prefix="/WEB-INF/view/"
            p:suffix=".jsp" /&gt;
  
      &lt;!--
      The index controller.
      --&gt;
      &lt;bean name="indexController"
            class="org.springframework.web.servlet.mvc.ParameterizableViewController"
            p:viewName="index" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>spring-sec.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.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security.xsd"&gt;
  
      &lt;!-- enable use-expressions --&gt;
      &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;intercept-url pattern="/login*" /&gt;
  
          &lt;!-- access denied page --&gt;
          &lt;access-denied-handler error-page="/403" /&gt;
          &lt;form-login 
              login-page="/login" 
              login-processing-url="/j_spring_security_check"
              default-target-url="/index"
              authentication-failure-url="/login?error" 
              username-parameter="j_username"
              password-parameter="j_password" /&gt;
          &lt;logout logout-success-url="/login?logout" /&gt;
      &lt;/http&gt;
  
      &lt;authentication-manager&gt;
          &lt;authentication-provider&gt;
              &lt;user-service&gt;
                  &lt;user name="abcd" password="abcd" authorities="ROLE_USER" /&gt;
              &lt;/user-service&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>login.jsp:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
  &lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  
      &lt;c:url value="j_spring_security_check" var="loginurl" /&gt;
      &lt;form action="${loginurl}" method="POST"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td colspan="2" align="center"&gt;Already have an account - Login&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Email&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" id="j_username" name="j_username" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password&lt;/td&gt;
                  &lt;td&gt;&lt;input type="password" id="j_password" name="j_password" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="2" align="center"&gt;&lt;input type="submit" value="Login" /&gt;&lt;/td&gt;
              &lt;/tr&gt;   
              &lt;tr&gt;
                  &lt;td colspan="2" align="center"&gt;
                      &lt;a href="${pageontext.request.contextPath }/forgotpassword"&gt;Forgot Password&lt;/a&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;                                   
          &lt;/table&gt;                                        
      &lt;/form&gt;
      &lt;span class="error"&gt;${loginMessage}&lt;/span&gt;
  </code></pre>
  
  <p>LoginController.java:</p>
  
  <pre><code>@Controller
  public class LoginController {
  
      @RequestMapping("/login")
      public ModelAndView indexController(ModelMap model)
      {       
          return new ModelAndView("login", "welcomeMessage","Hello Guest! welcome to our site");
      }
  }
  </code></pre>
  
  <p>Libraries used:</p>
  
  <pre><code>antlr-2.7.7
  aopalliance-1.0
  classmate-1.0.0
  commons-beanutils-1.8.0
  commons-digester-2.0
  commons-fileupload-1.3.1
  commons-io-2.4
  commons-logging-1.2
  dom4j-1.6.1
  hibernate-commons-annotations-4.0.5.Final
  hibernate-core-4.3.10.Final
  hibernate-jpa-2.1-api-1.0.0.Final
  hibernate-validator-5.1.3.Final
  jackson-annotations-2.5.0
  jackson-core-2.5.0
  jackson-databind-2.5.0
  jandex-1.1.0.Final
  javassist-3.18.1-GA
  javax.servlet-api-3.1.0
  javax.servlet.jsp-api-2.3.1
  jboss-logging-3.1.3.GA
  jboss-logging-annotations-1.2.0.Beta1
  jboss-transaction-api_1.2_spec-1.0.0.Final
  jcl-over-slf4j-1.7.6
  jstl-1.2
  mysql-connector-java-5.1.38
  slf4j-api-1.7.6
  spring-aop-4.1.1.RELEASE-javadoc
  spring-aop-4.1.1.RELEASE-sources
  spring-aop-4.1.1.RELEASE
  spring-aop-4.1.7.RELEASE
  spring-aspects-4.1.1.RELEASE-javadoc
  spring-aspects-4.1.1.RELEASE-sources
  spring-aspects-4.1.1.RELEASE
  spring-beans-4.1.1.RELEASE-javadoc
  spring-beans-4.1.1.RELEASE-sources
  spring-beans-4.1.1.RELEASE
  spring-beans-4.1.7.RELEASE
  spring-context-4.1.1.RELEASE-javadoc
  spring-context-4.1.1.RELEASE-sources
  spring-context-4.1.1.RELEASE
  spring-context-4.1.7.RELEASE
  spring-context-support-4.1.1.RELEASE-javadoc
  spring-context-support-4.1.1.RELEASE-sources
  spring-context-support-4.1.1.RELEASE
  spring-core-4.1.1.RELEASE-javadoc
  spring-core-4.1.1.RELEASE-sources
  spring-core-4.1.1.RELEASE
  spring-core-4.1.7.RELEASE
  spring-expression-4.1.1.RELEASE-javadoc
  spring-expression-4.1.1.RELEASE-sources
  spring-expression-4.1.1.RELEASE
  spring-expression-4.1.7.RELEASE
  spring-instrument-4.1.1.RELEASE-javadoc
  spring-instrument-4.1.1.RELEASE-sources
  spring-instrument-4.1.1.RELEASE
  spring-instrument-tomcat-4.1.1.RELEASE-javadoc
  spring-instrument-tomcat-4.1.1.RELEASE-sources
  spring-instrument-tomcat-4.1.1.RELEASE
  spring-jdbc-4.1.1.RELEASE-javadoc
  spring-jdbc-4.1.1.RELEASE-sources
  spring-jdbc-4.1.1.RELEASE
  spring-jdbc-4.1.7.RELEASE
  spring-jms-4.1.1.RELEASE-javadoc
  spring-jms-4.1.1.RELEASE-sources
  spring-jms-4.1.1.RELEASE
  spring-messaging-4.1.1.RELEASE-javadoc
  spring-messaging-4.1.1.RELEASE-sources
  spring-messaging-4.1.1.RELEASE
  spring-orm-4.1.1.RELEASE-javadoc
  spring-orm-4.1.1.RELEASE-sources
  spring-orm-4.1.1.RELEASE
  spring-orm-4.1.7.RELEASE
  spring-oxm-4.1.1.RELEASE-javadoc
  spring-oxm-4.1.1.RELEASE-sources
  spring-oxm-4.1.1.RELEASE
  spring-security-config-4.0.2.RELEASE
  spring-security-core-4.0.2.RELEASE
  spring-security-web-4.0.2.RELEASE
  spring-test-4.1.1.RELEASE-javadoc
  spring-test-4.1.1.RELEASE-sources
  spring-test-4.1.1.RELEASE
  spring-tx-4.1.1.RELEASE-javadoc
  spring-tx-4.1.1.RELEASE-sources
  spring-tx-4.1.1.RELEASE
  spring-tx-4.1.7.RELEASE
  spring-web-4.1.1.RELEASE-javadoc
  spring-web-4.1.1.RELEASE-sources
  spring-web-4.1.1.RELEASE
  spring-web-4.1.7.RELEASE
  spring-webmvc-4.1.1.RELEASE-javadoc
  spring-webmvc-4.1.1.RELEASE-sources
  spring-webmvc-4.1.1.RELEASE
  spring-webmvc-4.1.7.RELEASE
  spring-webmvc-portlet-4.1.1.RELEASE-javadoc
  spring-webmvc-portlet-4.1.1.RELEASE-sources
  spring-webmvc-portlet-4.1.1.RELEASE
  spring-websocket-4.1.1.RELEASE-javadoc
  spring-websocket-4.1.1.RELEASE-sources
  spring-websocket-4.1.1.RELEASE
  tiles-api-3.0.5
  tiles-autotag-core-runtime-1.1.0
  tiles-compat-3.0.5
  tiles-core-3.0.5
  tiles-el-3.0.5
  tiles-extras-3.0.5
  tiles-freemarker-3.0.5
  tiles-jsp-3.0.5
  tiles-mvel-3.0.5
  tiles-ognl-3.0.5
  tiles-request-api-1.0.6
  tiles-request-freemarker-1.0.6
  tiles-request-jsp-1.0.6
  tiles-request-mustache-1.0.6
  tiles-request-servlet-1.0.6
  tiles-request-servlet-wildcard-1.0.6
  tiles-request-velocity-1.0.6
  tiles-servlet-3.0.5
  tiles-template-3.0.5
  tiles-velocity-3.0.5
  validation-api-1.1.0.Final
  xml-apis-1.0.b2
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>HTTP Status 404 -
  
  type Status report
  
  message
  
  description The requested resource is not available.
  Apache Tomcat/7.0.41
  </code></pre>
  
  <p>Eclipse project</p>
  
  <pre><code>https://jumpshare.com/v/LQ8M1Bn7lBYGEBE100cb
  </code></pre>
  
  <p>I am not getting the root cause of the problem. I tried hard but every time I am getting the same error. Is it library not compatible or some other error? </p>
  
  <p>I am giving out the full project to test on your end, if you can find the error.</p>
  
  <p>Thanks</p>