4)dwz js框架根据statusCode==301,处理是跳转到登陆页面或者弹出登录dialog
java服务器端处理:
SessionValidateFilter中修改:
if ("XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With")) || request.getParameter("ajax") != null) { PrintWriter out = response.getWriter(); out.println({"statusCode":"301", "message":"Session Timeout! Please re-sign in!"}); } else { response.sendRedirect(response.encodeRedirectURL(this.loginUrl + java.net.URLEncoder.encode(backToUrl, "UTF-8"))); }
<script type="text/javascript"> $(function(){ DWZ.init("dwz.frag.xml", { // loginUrl:"loginsub.html", loginTitle:"登录", // 弹出登录对话框 loginUrl:"login.html", // 跳到登录页面 statusCode:{ok:200, error:300, timeout:301}, //【可选】 pageInfo:{pageNum:"pageNum", numPerPage:"numPerPage", orderField:"orderField", orderDirection:"orderDirection"}, //【可选】 debug:false, // 调试模式 【true|false】 callback:function(){ initEnv(); $("#themeList").theme({themeBase:"themes"}); } }); }); </script>
loadUrl: function(url,data,callback){ var $this = $(this); $.ajax({ type: 'POST', url: url, cache: false, data: data, success: function(response){ var json = DWZ.jsonEval(response); if (json.statusCode==DWZ.statusCode.timeout){ alertMsg.error(DWZ.msg("sessionTimout"), {okCall:function(){ DWZ.loadLogin(); }}); } if (json.statusCode==DWZ.statusCode.error){ if (json.message) alertMsg.error(json.message); } else { $this.html(response).initUI(); if ($.isFunction(callback)) callback(response); } }, error: DWZ.ajaxError }); }
ajaxDone:function (json){ if(json.statusCode == DWZ.statusCode.error) { if(json.message && alertMsg) alertMsg.error(json.message); } else if (json.statusCode == DWZ.statusCode.timeout) { if(json.message && alertMsg) alertMsg.error(json.message, {okCall:DWZ.loadLogin}); else DWZ.loadLogin(); } else { if(json.message && alertMsg) alertMsg.correct(json.message); }; }
{"statusCode":"301", "message":"Session Timeout! Please re-sign in!"}