1

我收到 HTTP 状态 404 - /SpringLogin/loginForm.jsp 错误

我试图创建一个将连接到数据库 mysql 的登录页面。我参考了“ www.a2ztechguide.com/2011/11/spring-security-login-example-using.html ”本教程。但我认为 spring-security.xml 中可能存在问题

另外,我没有使用依赖项,而是在 WEB-INF/lib 中手动添加了 jar,即

commons.logging-1.1.1.jar 
hibernate-validator-4.0.2.GA.jar 
javax.validation-1.0.0.GA.jar 
jstl-1.2.jar 
mysql-connector-java-5.1.9.jar 
org.springframework.aop-sources-3.0.5.RELEASE.jar 
org.springframework.web.servlet-3.0.5.RELEASE-A.jar 
spring-asm-3.0.5.RELEASE.jar 
spring-aspects-3.0.5.RELEASE.jar 
spring-beans-3.0.3.RELEASE.jar 
spring-context-3.0.5.RELEASE.jar 
spring-core-3.0.5.RELEASE.jar 
spring-expression-3.0.5.RELEASE.jar 
spring-jdbc-3.0.5.RELEASE.jar 
spring-security-acl-3.0.5.RELEASE-sources.jar 
spring-security-config-3.0.5.RELEASE.jar
spring-security-core-3.0.5.RELEASE.jar 
spring-security-taglibs-3.0.5.RELEASE.jar 
spring-security-web-3.0.5.RELEASE.jar 
spring-tx-3.0.5.RELEASE.jar 
spring-web-3.0.5.RELEASE.jar 
spring-webmvc-3.0.5.RELEASE.jar

控制台日志:

Sep 27, 2013 4:38:15 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.6.0_35/bin/../jre/bin/server;C:/Program Files/Java/jdk1.6.0_35/bin/../jre/bin;C:/Program Files/Java/jdk1.6.0_35/bin/../jre/lib/amd64;C:\Program Files\Java\jdk1.6.0_35\bin;C:\Program Files\Java\jdk1.6.0_35\bin;C:\Users\user\AppData\Roaming\npm;D:\eclipse;;.
Sep 27, 2013 4:38:15 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringLogin' did not find a matching property.
Sep 27, 2013 4:38:15 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 27, 2013 4:38:15 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 27, 2013 4:38:15 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 785 ms
Sep 27, 2013 4:38:15 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 27, 2013 4:38:15 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Sep 27, 2013 4:38:17 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
Sep 27, 2013 4:38:17 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags is already defined
Sep 27, 2013 4:38:17 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Sep 27, 2013 4:38:17 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Sep 27, 2013 4:38:17 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Fri Sep 27 16:38:17 IST 2013]; root of context hierarchy
Sep 27, 2013 4:38:17 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Sep 27, 2013 4:38:17 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-security.xml]
Sep 27, 2013 4:38:17 PM org.springframework.security.core.SpringSecurityCoreVersion <clinit>
INFO: You are running with Spring Security Core 3.0.5.RELEASE
Sep 27, 2013 4:38:17 PM org.springframework.security.config.SecurityNamespaceHandler <init>
INFO: Spring Security 'config' module version is 3.0.5.RELEASE
Sep 27, 2013 4:38:17 PM org.springframework.security.config.http.HttpSecurityBeanDefinitionParser checkFilterChainOrder
INFO: Checking sorted filter chain: [Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 300, Root bean: class [org.springframework.security.web.authentication.logout.LogoutFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, Root bean: class [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 800, Root bean: class [org.springframework.security.web.authentication.www.BasicAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1200, Root bean: class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1300, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1400, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1600, Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1800, <org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>, order = 1900]
Sep 27, 2013 4:38:18 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@31bf4bc8: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,welcomeController,org.springframework.web.servlet.view.InternalResourceViewResolver#0,dataSource,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.config.http.UserDetailsServiceInjectionBeanPostProcessor#0,org.springframework.security.filterChainProxy,org.springframework.security.provisioning.JdbcUserDetailsManager#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager]; root of factory hierarchy
Sep 27, 2013 4:38:18 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Sep 27, 2013 4:38:18 PM org.springframework.security.provisioning.JdbcUserDetailsManager initDao
INFO: No authentication manager set. Reauthentication of users when changing passwords will not be performed.
Sep 27, 2013 4:38:18 PM org.springframework.security.access.intercept.AbstractSecurityInterceptor afterPropertiesSet
INFO: Validated configuration attributes
Sep 27, 2013 4:38:18 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1135 ms
Sep 27, 2013 4:38:18 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Sep 27, 2013 4:38:18 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Sep 27, 2013 4:38:18 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Sep 27 16:38:18 IST 2013]; parent: Root WebApplicationContext
Sep 27, 2013 4:38:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Sep 27, 2013 4:38:18 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d3302a5: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,welcomeController,org.springframework.web.servlet.view.InternalResourceViewResolver#0,dataSource]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@31bf4bc8
Sep 27, 2013 4:38:18 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Sep 27, 2013 4:38:18 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/login.do] onto handler 'welcomeController'
Sep 27, 2013 4:38:18 PM org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'dispatcher': initialization completed in 369 ms
    Sep 27, 2013 4:38:18 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    Sep 27, 2013 4:38:18 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-bio-8009"]
    Sep 27, 2013 4:38:18 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 3220 ms

Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
   <display-name>SpringSecurityDemo</display-name>
            <description>SpringSecurityDemo</description>

            <servlet>
                        <servlet-name>dispatcher</servlet-name>
                        <servlet-class>org.springframework.web.servlet.DispatcherServlet
                        </servlet-class>
                        <load-on-startup>1</load-on-startup>
            </servlet>
            <servlet-mapping>
                        <servlet-name>dispatcher</servlet-name>
                        <url-pattern>*.do</url-pattern>
            </servlet-mapping>
            <listener>
                        <listener-class>org.springframework.web.context.ContextLoaderListener
                        </listener-class>
            </listener>

            <context-param>
                                    <param-name>contextConfigLocation</param-name>
                                    <param-value>
                                    /WEB-INF/dispatcher-servlet.xml,
                                    /WEB-INF/spring-security.xml
                                    </param-value>
            </context-param>

            <!-- Spring Security -->
            <filter>
                        <filter-name>springSecurityFilterChain</filter-name>
                        <filter-class>
                  org.springframework.web.filter.DelegatingFilterProxy
                </filter-class>
            </filter>
            <filter-mapping>
                        <filter-name>springSecurityFilterChain</filter-name>
                        <url-pattern>/*</url-pattern>
            </filter-mapping>

</web-app>

弹簧安全.xml:

    <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-3.0.xsd
                http://www.springframework.org/schema/security
                http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
        <http auto-config="true">
            <intercept-url pattern="/loginForm.jsp" filters="none" />
            <intercept-url pattern="/**" access="ROLE_USER" />
            <form-login login-page="/loginForm.jsp" default-target-url="/login.do"
                always-use-default-target="true" authentication-failure-url="/loginForm.jsp?login_error=1" />
            <logout logout-success-url="/loginForm.jsp" />
        </http>
        <authentication-manager>
            <authentication-provider>
                <jdbc-user-service data-source-ref="dataSource"
                    users-by-username-query="
                                  select username,password, enabled
                                  from users where username=?"
                    authorities-by-username-query="
                                  select u.username, ur.authority from users u, user_roles ur
                                  where u.user_id = ur.user_id and u.username=?" />
            </authentication-provider>
        </authentication-manager>
    </beans:beans>

调度程序-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config />

    <context:component-scan base-package="com.pkg.controller" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/logindb" />
        <property name="username" value="root" />
        <property name="password" value="admin" />
    </bean>

</beans>
4

2 回答 2

0

尝试将您的标签更改为:

 <form-login login-page="/login.do" default-target-url="/index.do" always-use-default-target="true" authentication-failure-url="/loginForm.jsp?login_error=1" /> 

(而不是 /index.do - 提供另一个页面)。

于 2013-09-27T12:32:44.983 回答
0

HTTP status 404表示找不到文件

服务器找不到loginForm.jsp

于 2013-09-27T11:34:46.690 回答