开发者

How to return different responses with a normal and ajax login in spring security 3

开发者 https://www.devze.com 2023-01-29 11:03 出处:网络
开发者_JAVA技巧I build a custom AuthenticationSuccessHandler so users can login using Ajax aswell use a normal login (for users with javascript disabled). To check if it\'s an ajax call or normal call

开发者_JAVA技巧I build a custom AuthenticationSuccessHandler so users can login using Ajax aswell use a normal login (for users with javascript disabled). To check if it's an ajax call or normal call I sent an extra request header. If it is an Ajax call i want to return some different code as on normal request. This results needs to come from a jsp file. I could sent the url back but than the user have to do another request to get the data. How can i read the output of the jsp file from within my code or is this a bad design?

This is how i handle the request.

@Override
public void onAuthenticationSuccess(HttpServletRequest request,
    HttpServletResponse response, Authentication auth) throws IOException,
    ServletException{
    if ("true".equals(request.getHeader("X-Ajax-call"))) {
        response.getWriter().print("Output of jsp file should go here?");

        response.getWriter().flush();
    } else {
        defaultHandler.onAuthenticationSuccess(request, response, auth);
    }
}


Can't you simply forward the request:

request.getRequestDispatcher("myFile.jsp").forward(request, repsponse);
0

精彩评论

暂无评论...
验证码 换一张
取 消