Xml 使用Spring安全性登录:请求方法';邮政';不支持
我无法使用Spring Security登录。登录页面显示良好,但每当我想实际登录时,就会出现以下错误: Etat HTTP 405-不支持请求方法“POST” 由于我使用的是Spring Security 4.0.1,请注意表单操作中使用的/login引用了Spring Security的内置身份验证引擎。因此,它与控制器中登录方法中的/login不同 以下是相关文件: login.jsp:Xml 使用Spring安全性登录:请求方法';邮政';不支持,xml,spring,spring-mvc,jakarta-ee,spring-security,Xml,Spring,Spring Mvc,Jakarta Ee,Spring Security,我无法使用Spring Security登录。登录页面显示良好,但每当我想实际登录时,就会出现以下错误: Etat HTTP 405-不支持请求方法“POST” 由于我使用的是Spring Security 4.0.1,请注意表单操作中使用的/login引用了Spring Security的内置身份验证引擎。因此,它与控制器中登录方法中的/login不同 以下是相关文件: login.jsp: <body onload='document.loginForm.username.focus(
<body onload='document.loginForm.username.focus();'>
<h1>Spring Security Custom Login Form (Annotation)</h1>
<div id="login-box">
<h2>Login with Username and Password</h2>
<c:if test="${not empty error}">
<div class="error">${error}</div>
</c:if>
<c:if test="${not empty msg}">
<div class="msg">${msg}</div>
</c:if>
<form name='loginForm'
action="<c:url value='/login' />" 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 colspan='2'>
<input name="submit" type="submit" value="submit" />
</td>
</tr>
</table>
<input type="hidden"
name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
</div>
spring-security.xml:
<body onload='document.loginForm.username.focus();'>
<h1>Spring Security Custom Login Form (Annotation)</h1>
<div id="login-box">
<h2>Login with Username and Password</h2>
<c:if test="${not empty error}">
<div class="error">${error}</div>
</c:if>
<c:if test="${not empty msg}">
<div class="msg">${msg}</div>
</c:if>
<form name='loginForm'
action="<c:url value='/login' />" 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 colspan='2'>
<input name="submit" type="submit" value="submit" />
</td>
</tr>
</table>
<input type="hidden"
name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
</div>
您正在进行
POST
呼叫服务,该呼叫显示为GET
@RequestMapping(value = "/login", method=RequestMethod.GET)
<form name='loginForm'
action="<c:url value='/login' />" method='POST'>
@RequestMapping(value=“/login”,method=RequestMethod.GET)
这就是您收到此邮件的原因。我刚刚发现了问题所在,在登录JSP中,我使用表达式语言来计算csrf参数名称和令牌,我只是忘记在登录页面中添加
属性。所有MainController
处理程序方法都映射为method=RequestMethod.GET
。我使用的是Spring security 4,据我所知,使用url/login而不是以前的/j_security_login_check with POST对用户进行身份验证。这通常会给我以下结构:-/login和GET:调用控制器以显示登录页面-/使用POST登录:调用spring安全认证机制。