http 404错误无法加载页面 [英] http 404 error not able to load the page

查看:173
本文介绍了http 404错误无法加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获得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

控制台日志:

  2013年9月27日4:38:15 PM org.apache.catalina.core。 AprLifecycleListener init 
INFO:在java.library.path中找不到基于APR的Apache Tomcat Native库,它允许生产环境中的最佳性能: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\\\
pm; D:\eclipse ;;。
2013年9月27日4:38:15 org.apache.tomcat.util.digester.SetPropertiesRule开始
警告:[SetPropertiesRule] {服务器/服务/引擎/主机/上下文}设置属性的源'到'org.eclipse.jst.jee.server:SpringLogin'没有找到匹配的属性。
2013年9月27日下午4:38:15 org.apache.coyote.AbstractProtocol init
INFO:初始化ProtocolHandler [http-bio-8080]
2013年9月27日4:38 :15 PM org.apache.coyote.AbstractProtocol init
INFO:初始化ProtocolHandler [ajp-bio-8009]
2013年9月27日下午4:38:15 org.apache.catalina.startup。 Catalina加载
INFO:初始化处理在785毫秒
2013年9月27日4:38:15 PM org.apache.catalina.core.StandardService startInternal
信息:启动服务Catalina
2013年9月27日下午4:38:15 org.apache.catalina.core.StandardEngine startInternal
INFO:启动Servlet引擎:Apache Tomcat / 7.0.42
2013年9月27日下午4:38:17 org.apache.catalina.startup.TaglibUriRule body
INFO:跳过TLD。 URI:http://www.springframework.org/tags/form已经定义
2013年9月27日4:38:17 PM org.apache.catalina.startup.TaglibUriRule body
信息:跳过TLD 。 URI:http://www.springframework.org/tags已经定义
2013年9月27日4:38:17 PM org.apache.catalina.core.ApplicationContext log
INFO:初始化Spring根WebApplicationContext
2013年9月27日4:38:17 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO:Root WebApplicationContext:初始化启动
2013年9月27日4:38:17 .springframework.context.support.AbstractApplicationContext prepareRefresh
信息:刷新根WebApplicationContext:启动日期[Fri Sep 27 16:38:17 IST 2013];根目录层次结构
2013年9月27日4:38:17 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO:从ServletContext资源加载XML bean定义[/ WEB-INF / dispatcher -servlet.xml]
2013年9月27日4:38:17 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO:从ServletContext资源加载XML bean定义[/ WEB-INF / spring-security.xml]
2013年9月27日4:38:17 PM org.springframework.security.core.SpringSecurityCoreVersion< clinit>
信息:您正在运行Spring Security Core 3.0.5.RELEASE
2013年9月27日4:38:17 PM org.springframework.security.config.SecurityNamespaceHandler< init>
信息:Spring Security'config'模块版本是3.0.5.RELEASE
2013年9月27日下午4:38:17 org.springframework.security.config.http.HttpSecurityBeanDefinitionParser checkFilterChainOrder
INFO :检查排序过滤器链:[root bean:class [org.springframework.security.web.context.SecurityContextPersistenceFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 300,Root bean:class [org.springframework.security.web.authentication.logout.LogoutFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 400,Root bean:class [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 800,Root bean:class [org.springframework.security.web.authentication.www.BasicAuthenticationFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 1200,Root bean:class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 1300,Root bean:class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 1400,Root bean:class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 1600,Root bean:class [org.springframework.security.web.session.SessionManagementFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 1700,Root bean:class [org.springframework.security.web.access.ExceptionTranslationFilter];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = null,order = 1800,< org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>,order = 1900]
2013年9月27日4:38:18 PM org.springframework.beans .factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO:在org.springframework.beans.factory.support.DefaultListableBeanFactory@31bf4bc8中预实例化单例:定义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,数据源,org.springframework.security.web .PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.web.authentication.session.SessionFixati onProtectionStrategy#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.UserDetailsS​​erviceInjectionBeanPostProcessor#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.springframew ork.security.authenticationManager];工厂层次结构
2013年9月27日4:38:18 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO:加载的JDBC驱动程序:com.mysql.jdbc.Driver
Sep 27,2013 4:38:18 PM org.springframework.security.provisioning.JdbcUserDetailsManager initDao
INFO:没有设置身份验证管理器。更改密码时用户的重新认证将不会被执行。
2013年9月27日下午4:38:18 org.springframework.security.access.intercept.AbstractSecurityInterceptor afterPropertiesSet
INFO:验证的配置属性
2013年9月27日4:38:18 .springframework.web.context.ContextLoader initWebApplicationContext
INFO:Root WebApplicationContext:初始化完成在1135 ms
2013年9月27日4:38:18 PM org.apache.catalina.core.ApplicationContext log
INFO:初始化Spring FrameworkServlet'dispatcher'
2013年9月27日4:38:18 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO:FrameworkServlet'dispatcher':初始化启动
2013年9月27日下午4:38:18 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO:刷新WebApplicationContext命名空间dispatcher-servlet:启动日期[Fri Sep 27 16:38:18 IST 2013] ; parent:Root WebApplicationContext
2013年9月27日4:38:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO:从ServletContext资源加载XML bean定义[/ WEB-INF / dispatcher -servlet.xml]
2013年9月27日4:38:18 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO:在org.springframework.beans.factory中实例化单例。 support.DefaultListableBeanFactory@1d3302a5:定义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,数据源]; parent:org.springframework.beans.factory.support.DefaultListableBeanFactory@31bf4bc8
2013年9月27日4:38:18 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO:加载的JDBC驱动程序:com .mysql.jdbc.Driver
2013年9月27日4:38:18 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO:映射的URL路径[/login.do]到处理程序' welcomeController'
2013年9月27日下午4:38:18 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO:FrameworkServlet'dispatcher':初始化在369 ms完成
2013年9月27日4:38:18 PM org.apache.coyote.AbstractProtocol start
INFO:启动ProtocolHandler [http-bio-8080]
2013年9月27日4:38:18 PM org.apache.coyote .AbstractProtocol start
INFO:启动ProtocolHandler [ajp-bio-8009]
2013年9月27日4:38:18 PM org.apache.catalina.startup.Catalina start
信息: 3220 ms服务器启动

Web.xml:

 <?xml version =1.0encoding =UTF-8?> 
< web-app xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns =http://java.sun.com/xml/ns/javaeexmlns :web =http://java.sun.com/xml/ns/javaee/web-app_2_5.xsdxsi:schemaLocation =http://java.sun.com/xml/ns/javaee http:// java.sun.com/xml/ns/javaee/web-app_3_0.xsdid =WebApp_IDversion =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>

spring-security.xml:

 < beans:beans xmlns =http://www.springframework.org/schema/security
xmlns:beans =http://www.springframework.org/ schema / beansxmlns: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 /模式/安全/弹簧安全3.0.3.xsd>
< http auto-config =true>
< intercept-url pattern =/ loginForm.jspfilters =none/>
< intercept-url pattern =/ **access =ROLE_USER/>
< form-login login-page =/ loginForm.jspdefault-target-url =/ login.do
always-use-default-target =trueauthentication-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 =
从用户选择用户名,密码,启用
用户名=?
authority-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>

dispatcher-servlet.xml:

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

< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema -instancexmlns: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 =driverClassNamevalue =com.mysql.jdbc.Driver/>
< property name =urlvalue =jdbc:mysql:// localhost:3306 / logindb/>
< property name =usernamevalue =root/>
< property name =passwordvalue =admin/>
< / bean>

< / beans>


解决方案

尝试将您的标签更改为:

 < form-login login-page =/ login.dodefault-target-url =/ index.doalways-use- default-target =trueauthentication-failure-url =/ loginForm.jsp?login_error = 1/> 

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


I am getting HTTP Status 404 - /SpringLogin/loginForm.jsp error

I was trying to create a login page which will be connected to database mysql. I referred " www.a2ztechguide.com/2011/11/spring-security-login-example-using.html " this tutorial. but in I think there might be a problem in spring-security.xml

Also instead of using dependencies I have added jars manually in WEB-INF/lib i.e

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

Console log:

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>

spring-security.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>

dispatcher-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>

解决方案

Try changing your tag to:

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

(instead of /index.do - provide another page).

这篇关于http 404错误无法加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆