1
我寫了一個定製Failure Handler
在我的春天應用如何使用DefaultRedirectStrategy的「POST」方法重定向?
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
方法。
我試圖添加attribute
和setHeader
,但無法得到我想要的。
請參閱http://stackoverflow.com/questions/14039121/can-sendredirect-act-as-a-post-method-instead-of-get-jsp-servlets –