本篇文章主要介绍了springmvc控制登录用户session失效后跳转登录页面,session一旦失效就需要重新登陆,有兴趣的同学可以了解一下。
springmvc控制登录用户session失效后跳转登录页面,废话不多少了,具体如下:
第一步,配置 web.xml
15
第二步,配置spring-mvc.xml
第三步,写拦截器SystemSessionInterceptor 方法
public class SystemSessionInterceptor implements handlerinterceptor { private static final String LOGIN_URL="/jsp/sessionrun.jsp"; @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSession session=request.getSession(true); //session中获取用户名信息 Object obj = session.getAttribute(CMConstant.LOGINUSER); if (obj==null||"".equals(obj.toString())) { response.sendRedirect(request.getSession().getServletContext().getcontextpath()+LOGIN_URL; return false; } return true; }
到此 springMvc拦截session失效后处理方式结束。