如何重定向使用方法" POST"通过DefaultRedirectStrategy?

时间:2015-10-18 11:40:55

标签: java spring spring-mvc spring-security

我在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方法{{1}方法。

我尝试添加GETattribute,但无法获得我想要的内容。

1 个答案:

答案 0 :(得分:0)

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