2015-10-18 56 views
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方法。

我試圖添加attributesetHeader,但無法得到我想要的。

+1

請參閱http://stackoverflow.com/questions/14039121/can-sendredirect-act-as-a-post-method-instead-of-get-jsp-servlets –

回答