婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Ajax Session失效跳轉(zhuǎn)登錄頁面的方法

Ajax Session失效跳轉(zhuǎn)登錄頁面的方法

熱門標簽:ai機器人電銷資源 超級大富翁地圖標注 云呼外撥網(wǎng)絡(luò)電話系統(tǒng) 機器人電銷騙局揭秘 地圖標注項目怎么樣 硅語電話機器人公司 個人怎樣在百度地圖標注地名 騰訊地圖標注位置能用多久 越南河內(nèi)地圖標注

在Struts應用中,我們發(fā)出的請求都會經(jīng)過 相應的攔截器進行相關(guān)處理,一般都會有一個用戶登錄攔截(Session失效攔截);一般請求的話,如果Session失效時,我們會跳到登錄頁面,可是如果我們采用AJAX請求時,將會返回登錄頁面的HTML代碼,這肯定不是我們想要的,那么我們?nèi)绾谓鉀Q呢?請看以下步驟:

一、建立攔截器

package com.xxx.planeap.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.xxx.common.contants.ConstantsKey;
import com.xxx.common.contants.SessionKey;
import com.xxx.planeap.domain.User;
import com.xxx.planeap.security.SecurityContextUtil;
/**
* 
* @author Goma OMA1989@YEAH.NET
* @version v1.0
* @since 2012-05-31
* 
*/
public class SecurityInterceptor extends AbstractInterceptor {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(SecurityInterceptor.class);
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
String className = invocation.getAction().getClass().getName();
String action = className.substring(className.lastIndexOf(".")+1,className.length());
String actionName = invocation.getProxy().getActionName();
String result;
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String type = request.getHeader("X-Requested-With");
User user = (User) ActionContext.getContext().getSession().get(SessionKey.CURRENT_USER);
if (user == null) {
logger.debug("SECURITY CHECKED: NEED TO LOGIN");
if ("XMLHttpRequest".equalsIgnoreCase(type)) {// AJAX REQUEST PROCESS
response.setHeader("sessionstatus", ConstantsKey.MSG_TIME_OUT);
result = null;
} else {// NORMAL REQUEST PROCESS
result = ActionSupport.LOGIN;
}
} else {
logger.debug("SECURITY CHECKED: USER HAS LOGINED");
SecurityContextUtil.setCurrentUser(user);
boolean hanPerm = SecurityContextUtil.hasPerm(action, actionName);
logger.debug("SECURITY CHECKED: PERMISSION---"+action+"."+actionName+"="+hanPerm);
result = invocation.invoke();
}
return result;
}
}

二、定義全局AJAX請求結(jié)束處理方法

//全局的AJAX訪問,處理AJAX清求時SESSION超時
$.ajaxSetup({
contentType:"application/x-www-form-urlencoded;charset=utf-8",
complete:function(XMLHttpRequest,textStatus){
//通過XMLHttpRequest取得響應頭,sessionstatus 
var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); 
if(sessionstatus=="timeout"){
//這里怎么處理在你,這里跳轉(zhuǎn)的登錄頁面
window.location.replace(PlanEap.getActionURI("login"));
}
}
});

也就是ajax發(fā)送請求時如果攔截返回一個表示就跳轉(zhuǎn),否則執(zhí)行正常操作。

您可能感興趣的文章:
  • Java Web實現(xiàn)session過期后自動跳轉(zhuǎn)到登陸頁功能【基于過濾器】
  • 詳解springmvc控制登錄用戶session失效后跳轉(zhuǎn)登錄頁面
  • php頁面跳轉(zhuǎn)session cookie丟失導致不能登錄等問題的解決方法
  • webix+springmvc session超時跳轉(zhuǎn)登錄頁面
  • jQuery ajax全局函數(shù)處理session過期后的ajax跳轉(zhuǎn)問題
  • ajax提交session超時跳轉(zhuǎn)頁面使用全局的方法來處理
  • Jsp中解決session過期跳轉(zhuǎn)到登陸頁面并跳出iframe框架的方法
  • Session過期后自動跳轉(zhuǎn)到登錄頁面的實例代碼
  • Session過期后實現(xiàn)自動跳轉(zhuǎn)登錄頁面

標簽:遼源 鄭州 海南 舟山 洛陽 內(nèi)蒙古 邢臺 林芝

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Ajax Session失效跳轉(zhuǎn)登錄頁面的方法》,本文關(guān)鍵詞  Ajax,Session,失效,跳轉(zhuǎn),登錄,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ajax Session失效跳轉(zhuǎn)登錄頁面的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于Ajax Session失效跳轉(zhuǎn)登錄頁面的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 金川县| 广水市| 泸水县| 伊金霍洛旗| 同江市| 类乌齐县| 威远县| 松阳县| 德安县| 昌邑市| 乐清市| 咸阳市| 大方县| 监利县| 喀喇| 三亚市| 新泰市| 都匀市| 北安市| 什邡市| 兴仁县| 和硕县| 沙河市| 龙州县| 东安县| 井研县| 丹棱县| 广东省| 长宁区| 祥云县| 进贤县| 永胜县| 敖汉旗| 拜泉县| 玉门市| 肇东市| 彰化县| 平定县| 阿图什市| 通渭县| 宣汉县|