解决使用iframe框架登录超时跳转的登录界面还在iframe里

一般使用filter过滤用户是否登录,如果用户没有登陆则转向登陆页面,这时候可以使用response.sendRedirect()。
但当在页面上使用了iframe后,发现被重定向的只是父页面中的iframe区域,登陆页面内容显示在该区域中。说明在过滤器中发送重定向请求时,是在iframe页面发送的。

 

  • 一般写法
//session 超时
if(currentUser == null) {
	// 未登录
	response.sendRedirect("/login/toLogin");
	return false;
}
  • 使用iframe

 

//session 超时
if(currentUser == null) {
	// 未登录
	PrintWriter out = response.getWriter();
	out.println("");
	out.println("");
	out.println("");
    return false;
}

使用 response.getWriter() 该方法可以将字符文本发送到浏览器。

关于  window.open ('/login/toLogin','_top')

解决使用iframe框架登录超时跳转的登录界面还在iframe里_第1张图片

你可能感兴趣的:(解决使用iframe框架登录超时跳转的登录界面还在iframe里)