session过期后自动跳转到登陆页
https://blog.csdn.net/zheng963/article/details/46773297
项目需要做一个自动登出的功能,查询了网上的资料,一开始准备用session监听做,按照下面方式配置监听器
1.在项目的web.xml文件中添加如下代码:
1 2 3 4 |
|
2.编写java类。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
配置完成后等session失效后成功进入sessionDestroyed方法,准备进行页面跳转操作,突然发现怎么写跳转,愣住了,继续上网请教大神,发现这个监听是做一些后台统计处理的,无法实现页面跳转的功能。
只能放弃这方法了,开始使用过滤器实现
1、web.xml中添加过滤器配置
1 2 3 4 5 6 7 8 |
|
2、新建SessionFilter类,实现Filter接口。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
3、客户端JS,用于ajax请求session超时
对于jquery
1 2 3 4 5 6 7 8 9 10 11 12 |
|
对于extjs的ajax请求
1 2 3 4 5 6 7 8 9 10 11 |
|
如果使某个ajax请求不受全局方法的影响,那么可以在使用$.ajax()方法时,将参数中的global设置为false,jquery代码如下:
1 2 3 4 |
|