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