处理jquery的ajax请求session过期跳转到登录页面
首先需要在拦截器中判断是否是ajax请求,如果是
if(isAjaxRequest(request)){//ajax请求
response.setHeader("sessionstatus", "timeout");
response.setHeader("redirectUrl", request.getContextPath()+Constant.LOGIN);
}else{//form请求
response.sendRedirect(request.getContextPath()+Constant.LOGIN);
}
传送两个参数出去。
在页面上定义上ajax的通用参数:
<!-- 处理Ajax的session过期开始 -->
<script type="text/javascript">
if(typeof($)!="undefined"){
$.ajaxSetup({
contentType:"application/x-www-form-urlencoded;charset=UTF-8",//发送信息至服务器时内容编码类型
complete:function(XMLHttpRequest,textStatus){
var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
if(sessionstatus!=null&&sessionstatus=="timeout"){
alert("Session过期...");
var redirectUrl = XMLHttpRequest.getResponseHeader("redirectUrl");
window.location.replace(redirectUrl);
}
}
});
}
</script>
<!-- 处理Ajax的session过期结束 -->
处理jquery的ajax请求session过期跳转到登录页面的更多相关文章
- Spring Security登录超时,angular ajax请求出错自动跳转至登录页(jQuery也适用)
公司开发采用Spring Security+AngualerJS框架,在session过期之后,ajax请求会直接出错.本文介绍如何实现出错情况下自动跳转至登录页. 整体思路是,session过期后, ...
- Ajax 请求session过期的统一处理
public class LoginInterceptor extends HandlerInterceptorAdapter { @SuppressWarnings("unused&quo ...
- 解决session过期跳转到登录页并跳出iframe框架(或者layui弹出层)
当用户长时间停留在管理界面没有操作,等到session过期后,进行了操作,那么只是iframe跳转到login页面,这不是我们想要的结果.解决方法:在login页面加一个逻辑判断: <scrip ...
- session过期跳转到登陆页面并跳出iframe框架的两个方法
最近在做拦截器,判断用户登录后操作超时,失去权限然后要重新登录,但是用的iframe,返回的登陆页总是在框架中显示,我百度了下,总是只有其中一个方法,现在分享下两种解决方法,希望对你们有帮助: 方法一 ...
- session过期跳转到登陆页面并解决跳出iframe问题
首先,先转载如下这篇博主写的关于后台系统使用iframe不能跳出的问题,地址:https://blog.csdn.net/xiaocen99/article/details/38521649 在ifr ...
- Jsp中解决session过期跳转到登陆页面并跳出iframe框架的方法
1.可以用javaScript解决在你想控制跳转的页面,比如login.jsp中的<head>与</head>之间加入以下代码: <script language=”Ja ...
- iframe session过期跳转到登陆页面
在login.jsp中添加js: if(window !=top){ top.location.href=location.href; } <script type="text/jav ...
- [JS] Ajax请求会话过期处理
对于页面来说,处理session过期比较简单,一般只需在过滤器里面判断session用户是否存在,不存在则跳转页面到登陆页即可. 对于Ajax请求来说,这个办法则无效,只能获取到登录页的html代码. ...
- Ajax请求会话过期处理(JS)
对于页面来说,处理session过期比较简单,一般只需在过滤器里面判断session用户是否存在,不存在则跳转页面到登陆页即可. 对于Ajax请求来说,这个办法则无效,只能获取到登录页的html代码. ...
随机推荐
- Build a Basic CRUD App with Vue.js and nodejs
https://developer.okta.com/blog/2018/02/15/build-crud-app-vuejs-node#add-authentication-with-okta I’ ...
- openvpn-LDAP验证
安装openvpn ldap apt-get install openvpn-auth-ldap mkdir -p /etc/openvpn/auth/ cp /usr/share/doc/openv ...
- [LeetCode] 709. To Lower Case_Easy
Implement function ToLowerCase() that has a string parameter str, and returns the same string in low ...
- 解决PuTTY中文乱码
转载:http://lhdeyx.blog.163.com/blog/static/3181969720091115113716947/ 打开putty,选择 Category中的Windows--- ...
- win7 x64安装TensorFlow
在windows下安装的TensorFlow做学习研究之用,如果要进行技术,请看相关博文:CentOS7安装TensorFlow 1.安装Pytho3.5 首先到Anaconda网站去下载Window ...
- Boost学习-Linuxidc上的很好的学习资料
来自 http://www.linuxidc.com/Linux/2011-07/39215.htm,拷贝第一页如下 Boost学习系列 简介及基本用法 [日期:2011-07-25] 来源:Linu ...
- python list seq
//test.py list1 = [1, 2, 3]list2 = [4, 5, 6] print cmp(list1, list2)print len(list1), len(list2)prin ...
- 查看手机cpu信息
adb shell getprop ro.product.cpu.abi
- HTTP参数污染【转】
HTTP参数污染注入源于网站对于提交的相同的参数的不同处理方式导致. 例如: www.XX.com/a?key=ab&key=3 如果服务端返回输入key的值,可能会有 一: ab 二:3 三 ...
- java资料共享
1.javascript视频教程 链接: http://pan.baidu.com/s/1gd57FVH 密码: d9ei 2.JPA视频教程 链接: http://pan.baidu.com/s/1 ...