gpt4 book ai didi

java - Spring-mvc 与 spring security 获取 HTTP 状态 405 - 不支持请求方法 'POST'

转载 作者:行者123 更新时间:2023-12-02 11:32:14 25 4
gpt4 key购买 nike

如果首先单击提交按钮, session 不存在,然后它路由到 login.jsp 页面并且流程正常,但如果假设首先使用提交按钮无法路由到的任何其他权限登录,则会发生问题所需的页面,登录后单击提交按钮,因此在这种情况下,应该路由到“authentication-failure-url =“/loginFailure.web”或访问被拒绝,但它会抛出 HTTP Status 405 - Request method '不支持 POST

另外,在响应头中,可以看到允许:获取为什么它只允许到达这里?

根据要求发送额外参数_csrf:e15bc9a6-66jh-4de4-b278-008e6f9a569c因为这样的 Spring 表单默认添加它,可能是它引起的问题?

或者请让我知道解决此问题的任何解决方案

先谢谢了!!!!

@RequestMapping(value = "/searchCriteria.web", method = RequestMethod.POST, params = "searchButton")
public String getsearchCriteria(@ModelAttribute("rentalVO") RentalVO rental, Model model) {
List<Vehicle> vehicles;
try {
vehicles = rentalService.findVehiclesBetweenDates(rental.getStart(),rental.getEnd());
} catch (InvalidDateException e) {
model.addAttribute("message", "Booking cannot be preoceeded !! Invalid dates provided");
return "message";
}
model.addAttribute("vehicles", vehicles);
model.addAttribute("start",rental.getStart());
model.addAttribute("end",rental.getEnd());
return "bookVehicle";
}

登录.jsp

<form name='loginForm'
action="<c:url value='/j_spring_security_check' />" method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_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>

spring-security.xml

<http use-expressions="true" auto-config="true">
<access-denied-handler error-page="/403" />
<intercept-url pattern="/categoryCriteria*"
access="hasAnyRole('ROLE_ADMIN','ROLE_USER','ROLE_DB')" />
<intercept-url pattern="/searchAllCriteria*" access="hasAnyRole('ROLE_ADMIN')" />
<intercept-url pattern="/searchCriteria*"
access="hasAnyRole('ROLE_ADMIN','ROLE_DB')" />
<!-- <intercept-url pattern="/bookVehicle*"
access="hasAnyRole('ROLE_ADMIN','ROLE_DB')" /> -->
<form-login login-page="/login.web" default-target-url="/login.web"
authentication-failure-url="/loginFailure.web" username-parameter="j_username"
password-parameter="j_password" login-processing-url="/j_spring_security_check" />
<logout logout-url="/j_spring_security_logout"
logout-success-url="/index.web" />
<csrf/>
<!-- <csrf disabled="true"/> -->
</http>

index.jsp

<td><form:form action="searchCriteria.web" method="post"
commandName="rental">
<b> Check the Car availability as per your time frame (Admin Db access) </b>
<br>
<br>
Start date: <form:input path="start" id="datepickerStart" />
<br>
<br>
End date: <form:input path="end" id="datepickerEnd" />
<br>
<br>
<input type="submit" value="Available Car" name="searchButton" />
</form:form></td>
</tr>

最佳答案

我遇到了这个问题,在这里,提交按钮正在对后端进行 POST 调用,由于用户身份验证本身而失败,并由 spring security 路由到/loginFailure.web,而处理 loginFailure.web url 的方法是 GET 方法,最终给出 405。因为它甚至没有到达 Controller 方法/searchCriteria.web ,该方法本身被 spring security 拦截并路由到其他失败身份验证网址。

关于java - Spring-mvc 与 spring security 获取 HTTP 状态 405 - 不支持请求方法 'POST',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49210261/

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