session过期跳转到登陆页面并跳出iframe框架的两个方法
2016-08-04 00:33
344 查看
原文章地址:http://1008610086.blog.51cto.com/4995677/1538464
最近在做拦截器,判断用户登录后操作超时,失去权限然后要重新登录,但是用的iframe,返回的登陆页总是在框架中显示,我百度了下,总是只有其中一个方法,现在分享下两种解决方法,希望对你们有帮助:
方法一:
一般使用filter过滤用户是否登录,如果用户没有登陆则转向登陆页面,这时候可以使用response.sendRedirect()。
但当在页面上使用了iframe后,发现被重定向的只是父页面中的iframe区域,登陆页面内容显示在该区域中。说明在过滤器中发送重定向请求时,是在iframe页面发送的。错误的代码如下:
因为response.sendRedirect()没有target属性,但html页面和js中有,于是,当判断出用户没有访问权限时,我们可以在jsp中使用js来转向到真正的登录页面。在filter类的doFilter方法中添加如下代码:(跳转的路径通过request.getRequestURI()获取)
最近在做拦截器,判断用户登录后操作超时,失去权限然后要重新登录,但是用的iframe,返回的登陆页总是在框架中显示,我百度了下,总是只有其中一个方法,现在分享下两种解决方法,希望对你们有帮助:
方法一:
一般使用filter过滤用户是否登录,如果用户没有登陆则转向登陆页面,这时候可以使用response.sendRedirect()。
但当在页面上使用了iframe后,发现被重定向的只是父页面中的iframe区域,登陆页面内容显示在该区域中。说明在过滤器中发送重定向请求时,是在iframe页面发送的。错误的代码如下:
HttpServletRequest req = (HttpServletRequest) request; Visitor visitor = (Visitor) req.getSession().getAttribute("visitor"); if (visitor == null) { ((HttpServletResponse) response).sendRedirect("/smpc/login/login.jsp"); } chain.doFilter(request, response);
因为response.sendRedirect()没有target属性,但html页面和js中有,于是,当判断出用户没有访问权限时,我们可以在jsp中使用js来转向到真正的登录页面。在filter类的doFilter方法中添加如下代码:(跳转的路径通过request.getRequestURI()获取)
User user = (User) req.getSession().getAttribute("session_user"); if (user == null) { java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<script>"); out.println("window.open ('/smpc/login/login.jsp','_top')"); out.println("</script>"); out.println("</html>"); return; } 方法二: 在你想控制跳转的页面,比如login.jsp中的<head>与</head>之间加入以下代码: <script language="JavaScript"> if (window != top) top.location.href = location.href; </script>
相关文章推荐
- session过期跳转到登陆页面并跳出iframe框架的两个方法
- session过期跳转到登陆页面并跳出iframe框架的最简单方法
- Jsp中解决session过期跳转到登陆页面并跳出iframe框架的方法
- Jsp中解决session过期跳转到登陆页面并跳出iframe框架的方法
- 解决session过期跳转到登陆页面并跳出iframe框架
- 解决session过期跳转到登陆页面并跳出iframe框架
- 解决session过期跳转到登陆页面并跳出iframe框架
- 解决session过期超时跳转到登陆页面并跳出iframe框架
- 解决session过期跳转到登陆页面并跳出iframe框架
- 解决session过期跳转到登陆页面并跳出iframe框架
- 解决session过期跳转到登陆页面并跳出iframe框架
- [置顶]解决session过期跳转到登陆页面并跳出iframe框架
- Form验证 解决过期超时跳转到登陆页面并跳出iframe框架
- session过期跳转到登陆页面并跳出iframe框架
- frame框架-用户session失效仅在iframe中跳转登录页面的解决方法
- session过期让登录页面跳出iframe的方法
- 兼容解决 IE 和(火狐)FF中 Iframe框架的页面缓存的方法
- [置顶] 兼容解决 IE 、火狐、谷歌浏览器中 Iframe框架的页面缓存的方法
- 织梦系统DedeCMS设定栏目及文档权限登录后跳转到登陆前的页面的实现方法