重定向跳出父Frame

當session過時後能夠用過濾器來設置重定向頁面javascript

代碼以下:java


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中的<head>與</head>之間加入如下代碼:session

代碼以下:

<script language=」JavaScript」>
  if (window != top)
  top.location.href = location.href;
</script>


JS刷新框架的腳本語句框架

複製代碼 代碼以下:


//如何刷新包含該框架的頁面用  
<script language=JavaScript>
   parent.location.reload();
</script> 
//子窗口刷新父窗口
<script language=JavaScript>
    self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a>   )
//如何刷新另外一個框架的頁面用  
<script language=JavaScript>
   parent.另外一FrameID.location.reload();
</script>
若是想關閉窗口時刷新或者想開窗時刷新的話,在<body>中調用如下語句便可。
<body onload="opener.location.reload()"> 開窗時刷新
<body onUnload="opener.location.reload()"> 關閉時刷新
<script language="javascript">
window.opener.document.location.reload()
</script>jsp

相關文章
相關標籤/搜索