spring中session管理
来源:互联网 发布:ps美工字体打包下载 编辑:程序博客网 时间:2024/06/01 09:42
假设:在用户登录系统一段时间没有操作后,session失效,如果这时用户有操作时应该跳转到登录页面要求重新登录。
一般解决方法:
(1)用户首次登录成功时,将用户对象存入session,如 session.setAttibute("loginUser", user);
(2)定义拦截器,对于所有关于某中url请求进行拦截,然后获取loginUser的对象,如果不存在,那么session过期:
- import org.springframework.stereotype.Repository;
- import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
- @Repository
- public class LoginInterceptor extends HandlerInterceptorAdapter {
- @Override
- public boolean preHandle(HttpServletRequest request,
- HttpServletResponse response, Object handler) throws Exception {
- Object obj = request.getSession().getAttribute("loginUser");
- if(obj==null){
- request.getRequestDispatcher("/login.jsp").forward(request, response);
- return false;
- }
- else{
- return super.preHandle(request, response, handler);
- }
- }
- }
如果发现session失效,将会跳转到login.jsp要求重新登录。
- <mvc:interceptors>
- <mvc:interceptor>
- <mvc:mapping path="/*.html"/>
- <bean class="com.xx.xxx.util.LoginInterceptor" />
- </mvc:interceptor>
- </mvc:interceptors>
0 0
- spring中session管理
- 【web开发】spring中session管理
- Spring如何管理Session
- Spring 管理的Session
- Spring管理Session
- spring 管理hibernate session
- Spring Session管理
- tomcat & spring session管理
- spring 管理session
- 用spring-session来管理http session
- 使用Spring Session和Redis管理session
- 分布式,使用spring-session管理session
- 通过Spring Session实现Session集中管理
- 使用Spring Session和Redis管理session
- 使用Spring Session 进行分布式Session管理
- 通过Spring Session实现Session集中管理
- Spring整合Hibernate【Session管理】
- Spring整合Hibernate【Session管理】
- CSharp文件读取与写入入门图解
- android第一个程序hello world
- 从安卓recovery 的 backup 备份数据中手动恢复 通讯录、短信,或者其他软件中的信息的方法
- 从CSV文件中读取数据,使用逗号','分割问题
- 基本的二分查找算法
- spring中session管理
- centos6.4 安装 mysql5.5 confilt冲突 mysql5.1 lib 解决
- Codeforces Round #274 (Div. 2) B
- SSD7数据库系统实验Exercise2答案
- C++ 60分钟入门教程 - 2、C++与C语言的区别
- 让js具有面向对象的特性
- while中使用List.iterator().hasNext()为什么会出现无限循环
- 《实例妙解 Cocos2d-x 游戏开发》反馈勘误
- 在omnet++上仿真无线传感网络1