gpt4 book ai didi

java - 找不到 HTTP 请求的映射 Spring Security

转载 作者:行者123 更新时间:2023-12-01 10:53:03 25 4
gpt4 key购买 nike

我的项目遇到一些问题。

我可以成功进入登录页面,但单击提交按钮后出现此错误:

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>

有人可以帮助我吗?谢谢

最佳答案

您必须使用 /login 而不是 /j_spring_security_check 或将 login-processing-url 配置为 /j_spring_security_check >,参见 Spring Security Reference :

  • login-processing-url Maps to the filterProcessesUrl property of UsernamePasswordAuthenticationFilter. The default value is "/login".

关于java - 找不到 HTTP 请求的映射 Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33739183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com