欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

webix+springmvc session超時(shí)跳轉(zhuǎn)登錄頁面

 更新時(shí)間:2016年10月30日 13:53:14   作者:說我  
這篇文章主要介紹了webix+springmvc session超時(shí)跳轉(zhuǎn)登錄頁面的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下

引言

最近做項(xiàng)目,發(fā)現(xiàn)ajax請(qǐng)求不能在服務(wù)器中直接重定向到登錄頁面。查了些資料發(fā)現(xiàn)jquery的ajax請(qǐng)求有人給出了方法。但是webix的ajax請(qǐng)求和jquery的有些區(qū)別。這里模仿jquery的處理方式實(shí)現(xiàn)webix的ajax請(qǐng)求session超時(shí)跳轉(zhuǎn)。

具體的做法:

1、查看webix.js源碼發(fā)現(xiàn)webix.ajax只有請(qǐng)求前的監(jiān)聽函數(shù) "onBeforeAjax", 要做到獲取返回狀態(tài)跳轉(zhuǎn)登錄頁面必須要有個(gè)返回的監(jiān)聽函數(shù),但是源碼沒有。所以我修改了下源碼,加了個(gè)返回的監(jiān)聽函數(shù)"onAfterAjax"。

紅色標(biāo)記部分是我加的代碼,當(dāng)檢測(cè)到ajax完成時(shí),自動(dòng)執(zhí)行"onAfterAjax"。(代碼的位置可以搜索webix.js ,條件"onBeforeAjax",然后在對(duì)應(yīng)的位置加入紅色代碼就行

if (webix.callEvent("onBeforeAjax", [s, t, e, a, o, null, r])) {
var h = !1;
if ("GET" !== s) {
var l = !1;
for (var c in o)"content-type" == c.toString().toLowerCase() && (l = !0, "application/json" == o[c] && (h = !0));
l || (o["Content-Type"] = "application/x-www-form-urlencoded")
}
if ("object" == typeof e)if (h)e = this.stringify(e); else {
var u = [];
for (var d in e) {
var f = e[d];
(null === f || f === webix.undefined) && (f = ""), "object" == typeof f && (f = this.stringify(f)), u.push(d + "=" + encodeURIComponent(f))
}
e = u.join("&")
}
e && "GET" === s && (t = t + (-1 != t.indexOf("?") ? "&" : "?") + e,
e = null), a.open(s, t, !this.H);
var b = this.Tw;
b && (a.responseType = b);
for (var c in o)a.setRequestHeader(c, o[c]);
var x = this;
return this.master = this.master || n, a.onreadystatechange = function () {
if (!a.readyState || 4 == a.readyState) {
if (webix.callEvent("onAfterAjax", [a]) === !1) {
return false;
};
if (webix.ajax.count++, i && x && !a.aborted) {
if (-1 != webix.ly.find(a))return webix.ly.remove(a);
var t, e, s = x.master || x, r = a.status >= 400 || 0 === a.status;
"blob" == a.responseType || "arraybuffer" == a.responseType ? (t = "", e = a.response) : (t = a.responseText || "", e = x.J(a)), webix.ajax.$callback(s, i, t, e, a, r)
}
x && (x.master = null), i = x = n = null
}
}, this.qh && (a.timeout = this.qh), this.H ? a.send(e || null) : setTimeout(function () {
a.aborted || (-1 != webix.ly.find(a) ? webix.ly.remove(a) : a.send(e || null));
}, 1), this.master && this.master.Ve && this.master.Ve.push(a), this.H ? a : r
}

2、webix.ajx請(qǐng)求沒有明顯的標(biāo)志,jquery.ajax的標(biāo)識(shí)是x-requested-with ,所以我模擬給了個(gè)標(biāo)識(shí)requestFlag="webix"(可以自己設(shè)置個(gè)喜歡的),用"onBeforeAjax"設(shè)置

webix.attachEvent("onBeforeAjax",function(s, t, e, a, o){o["requestFlag"]="webix"})

3、監(jiān)聽返回狀態(tài)

webix.attachEvent("onAfterAjax",function(xhr){if(xhr.getResponseHeader("sessionstatus")=='timeout'){window.location.href='/webix/login.html'}});

4、后臺(tái)代碼

4.1 攔截器代碼

package com.ljx.filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
public class UserInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
}
@Override
public void postHandle(HttpServletRequest arg0,
HttpServletResponse response, Object arg2, ModelAndView arg3)
throws Exception {
response.sendRedirect("/webix/login.html");
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
Object obj = request.getSession().getAttribute("LOGIN");
if (null == obj) { // 未登錄
if (request.getHeader("requestFlag") != null
&& request.getHeader("requestFlag").equalsIgnoreCase(
"webix")) { // 如果是ajax請(qǐng)求響應(yīng)頭會(huì)有,requestFlag
response.setHeader("sessionstatus", "timeout");// 在響應(yīng)頭設(shè)置session狀態(tài)
} else {
response.sendRedirect(request.getContextPath() + "/login");
}
return false;
}
return true;
}
}

4.2 spring配置文件加入攔截器配置

<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/mvc/*" />
<bean class="com.ljx.filter.UserInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>

4.3 在F12控制臺(tái)執(zhí)行下webix.ajax查看效果

webix.ajax().get("/webix/mvc/login.action")

以上所述是小編給大家介紹的webix+springmvc session超時(shí)跳轉(zhuǎn)登錄頁面,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的。

相關(guān)文章

最新評(píng)論