Jsp中解決session到期跳轉到登陸頁面並跳出iframe架構

來源:互聯網
上載者:User

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

 代碼如下 複製代碼

<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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.