springMVC拦截器不能转跳页面怎么解决?

springMVC拦截器HandlerInterceptor,重写preHandle方法,用response.sendRedirect("/login.do");转跳页面,发现页面不能转跳,不知道为什么,但好像是因为页面包含异步Ajax导致。求解决办法。

拦截器里preHandle的返回值类型是boolean.我一般都是在拦截器里如果有问题的时候抛出异常,然后在异常处理handler里判断是同步还是异步请求,同步的直接重定向页面,异步的话返回页面中js来处理

大神能具体点吗?以下是我的代码,就是想实现用户权限控制。

public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {

    String contextPath=request.getContextPath();
    HttpSession session = request.getSession();
    String username = (String) session.getAttribute("username");
    if (username != null) {
        return true;
    }
    // 不符合条件的,跳转到登录界面
    response.sendRedirect(contextPath+"/main/login.jsp");
    return false;
}