gpt4 book ai didi

java - 出现 org.springframework.web.servlet.PageNotFound 错误handleHttpRequestMethodNotSupported

转载 作者:行者123 更新时间:2023-12-01 11:15:10 27 4
gpt4 key购买 nike

我已点击链接Example Link 创建登录应用程序。我没有在项目中使用maven。

当我运行应用程序时http://localhost:9889/SpringMVCDemo/login

重定向到下面的链接

http://localhost:9889/SpringMVCDemo/j_spring_security_check

我收到以下错误。

在控制台中,我收到以下错误消息

INFO: Server startup in 18487 ms
Aug 10, 2015 4:07:54 PM org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported

在浏览器中

HTTP Status 405 - Request method 'POST' not supported
type Status report

message Request method 'POST' not supported

description The specified HTTP method is not allowed for the requested resource.
<小时/>

Apache Tomcat/8.0.24

编辑:登录.jsp

<html>
<head><title>Login</title></head>
<body>
<h1>Login</h1>
<form name='f' action="j_spring_security_check" method='POST' >
<table>
<tr>
<td>User:</td>
<td><input type='text' name='username' value=''></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>

Spring 安全

<?xml version="1.0" encoding="UTF-8"?>
<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">


<http use-expressions="true">
<intercept-url pattern="/" access="isAnonymous()" />
<intercept-url pattern="/welcome" access="isAnonymous()" />
<intercept-url pattern="/login" access="isAnonymous()" />
<intercept-url pattern="/logout" access="isAnonymous()" />


<intercept-url pattern="/userInfo"
access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')" />
<intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/other/**" access="isAuthenticated()" />

<access-denied-handler error-page="/403" />

<form-login login-page='/login' login-processing-url="/j_spring_security_check"
default-target-url="/userInfo" always-use-default-target="false"
authentication-failure-url="/login?error=true" username-parameter="username"
password-parameter="password" />

<logout logout-url="/logout" logout-success-url="/logoutSuccessful"
delete-cookies="JSESSIONID" invalidate-session="true" />

</http>

<authentication-manager>
<authentication-provider>
<user-service>
<user name="user1" password="12345" authorities="ROLE_USER" />
<user name="admin1" password="12345" authorities="ROLE_USER, ROLE_ADMIN" />
</user-service>
</authentication-provider>



<!-- authentication from database -->
<authentication-provider>
<jdbc-user-service data-source-ref="myDataSource"
users-by-username-query="select username,password, enabled from users where username=?"
authorities-by-username-query="select username, role from users where username=?" />
</authentication-provider>

</authentication-manager>

</beans:beans>

我已经阅读了堆栈溢出中的一些答案,但没有找到解决方案。

有人可以帮助我吗?

最佳答案

感谢@JohnnyAW 建议在网上进行更多研发,我找到了在登录页面中实现 CSRF token 所需的答案。

当我在登录页面添加上述行时,它工作正常。

关于java - 出现 org.springframework.web.servlet.PageNotFound 错误handleHttpRequestMethodNotSupported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31917721/

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