session過期 ajax訪問不能返回登錄頁面問題

 $(function(){
        //處理AJAX的session過期問題  
        $.ajaxSetup({   
            contentType:"application/x-www-form-urlencoded;charset=utf-8",   
            cache:false ,   
            complete:function(XHR,TS){   
                var resText=XHR.responseText;   
                if(resText!=null && resText.indexOf("sessionState:0")>0){   
                     alert("您的登錄已超時,請重新登錄");
                     document.location.href=path + '/login/logout.do';   
                     //showMsg("您的登錄已超時, 請重新登錄!",'error');  
                }   
            }   
        });

    });


Filter

Object obj = session.getAttribute(Constants.LOGIN_SESSION);

            if (obj == null || "".equals(obj)) {
                if (req.getHeader("x-requested-with") != null
                        && req.getHeader("x-requested-with").equalsIgnoreCase(
                                "XMLHttpRequest")) {
                    PrintWriter printWriter = res.getWriter();
                    printWriter.print("{sessionState:0,url:"
                            + req.getContextPath() + "}");
                    printWriter.flush();
                    printWriter.close();
                }
            }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章