解决session过期超时跳转到登陆页面并跳出iframe框架



当session过期后可以用过滤器来设置重定向页面。


public class ActionFilter extends HttpServlet implements Filter {
 private FilterConfig filterConfig;

 public void init(FilterConfig config) {
  this.filterConfig = config;
 }

 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
  HttpServletRequest req = (HttpServletRequest) servletRequest;
  servletRequest.setCharacterEncoding("UTF-8");
  HttpServletResponse res = (HttpServletResponse) servletResponse;
  String url = req.getRequestURI();
  SysUserVOImpl user = (SysUserVOImpl) req.getSession().getAttribute("SysUser");

  if (null == user) {
   if (!COMMON.isEmpty(url) && (url.endsWith("newestlogin.jsp") || url.endsWith("UserLoginAction.jsp") || url.endsWith("login.jsp") || url.endsWith("loginAction.do"))) {
    filterChain.doFilter(servletRequest, servletResponse);
   } else {
    req.getRequestDispatcher("/newestlogin.jsp").forward(req, res);
   }
  } else {
   filterChain.doFilter(servletRequest, servletResponse);
  }
 }

但是这样不能不能跳出iframe等框架。


可以用javaScript解决
在你想控制跳转的页面,比如login.jsp中的与之间加入以下代码:

 

特点,简单易实现

缺点,可能需要跳转两次,如果第二次跳转较慢还会在ifream中显示第一次的界面内容


你可能感兴趣的:(web前端)