【发布时间】:2016-02-17 18:37:21
【问题描述】:
我的项目有问题。
我可以成功进入登录页面,但点击提交按钮后,我收到此错误:
Lis 16, 2015 4:30:01 ODP. org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/j_spring_security_check] in DispatcherServlet with name 'mvc-dispatcher'
从 jsp 中的这一行开始:
<form name='loginForm'
action="<c:url value='/j_spring_security_check' />" method='POST'>
这是我的 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-4.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<http auto-config="true">
<intercept-url pattern="/adminPage**" access="hasRole('ROLE_USER')" />
<form-login
login-page="/login"
default-target-url="/"
authentication-failure-url="/login?error"
username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<csrf/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="kk" password="1" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
这是我的 web.xml
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</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/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>
有人可以帮我吗?谢谢
【问题讨论】:
-
当您将 url 从 /j_spring_security_check 更改为 j_spring_security_check 而没有前导斜杠时会发生什么?
-
它不起作用。它显示红色,我无法在代码中更改它。
-
/j_spring_security_check 其中应用程序上下文将是 /mvc-dispatcher/spring_security_check - 您应该能够在登录页面中更改表单的操作方法。 -
这样我得到:警告:在 DispatcherServlet 中找不到带有 URI [/mvc-dispatcher/j_spring_security_check] 的 HTTP 请求的映射,名称为“mvc-dispatcher”
标签: java spring spring-mvc spring-security mapping