簡體   English   中英

作為org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported獲取錯誤

[英]Getting Error as org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported

我已按照鏈接示例鏈接創建了登錄應用程序。 我沒有為該項目使用過Maven。

當IAM運行應用程序http:// localhost:9889 / SpringMVCDemo / login時

重定向到下面的鏈接

http:// localhost:9889 / SpringMVCDemo / j_spring_security_check

我收到以下錯誤。

在控制台IAM中獲取以下錯誤消息

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

編輯: Login.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>

春季安全

<?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令牌所需的答案。

當我在登錄頁面中添加以上行時,它可以正常工作。

最簡單的方法是在登錄表單中將請求方法更改為“ GET”。 loginPage.jsp更改表單:

<form name='f' action="j_spring_security_check" method='GET'>

編輯:實際上,您不想將登錄請求作為“ GET”請求發送,因為您將能夠在日志文件中看到憑據。 可以進行測試,但是在某些時候,您需要將請求更改為“ POST”

在將角度應用程序與Spring集成時遇到了類似的問題。 考慮將此修復程序作為答案來幫助未來的讀者。

根據這里帖子 ,我已經在Spring Security中啟用了基本身份驗證,並嘗試從angular應用程序發出登錄請求。

http.post(this.loginUrl, {}, options);

由於基本身份驗證不接受POST方法,因此出現以下錯誤,

Aug 30, 2017 5:47:30 PM org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported

為了解決此問題,我只是如下更改了angular應用程序中的服務調用即可。

http.request(this.loginUrl, options);

實際使用CSRF令牌-

<form name='f' action="j_spring_security_check?${_csrf.parameterName}=${_csrf.token}" method='POST' >

希望這會起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM