【问题标题】:How can i redirect using method "POST" by DefaultRedirectStrategy?如何使用 DefaultRedirectStrategy 的方法“POST”重定向?
【发布时间】:2015-10-18 11:40:55
【问题描述】:

我在我的 Spring 应用中编写了一个自定义 Failure Handler

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler{
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
            AuthenticationException exception) throws IOException, ServletException {
        DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
        request.setAttribute("X-Http-Method-Override", "POST");
        response.setHeader("X-Http-Method-Override", "POST");

        redirectStrategy.sendRedirect(request, response, "/login");
    }

}

我想做的是:如果登录失败,我想redirect 到另一个页面/login,但使用POST 方法而不是GET 方法。

我尝试添加attributesetHeader,但无法得到我想要的。

【问题讨论】:

标签: java spring spring-mvc spring-security


【解决方案1】:

不!!!你不能有一个没有黑客的帖子重定向。作为参考,你可以看看 https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    • 2013-10-04
    • 1970-01-01
    • 2021-06-02
    • 2011-02-05
    • 1970-01-01
    • 2020-06-28
    相关资源
    最近更新 更多