當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(“l(fā)ogin.jsp”) || url.endsWith(“l(fā)oginAction.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>
您可能感興趣的文章:- Java Web實現(xiàn)session過期后自動跳轉到登陸頁功能【基于過濾器】
- 詳解springmvc控制登錄用戶session失效后跳轉登錄頁面
- php頁面跳轉session cookie丟失導致不能登錄等問題的解決方法
- webix+springmvc session超時跳轉登錄頁面
- jQuery ajax全局函數(shù)處理session過期后的ajax跳轉問題
- ajax提交session超時跳轉頁面使用全局的方法來處理
- Session過期后自動跳轉到登錄頁面的實例代碼
- Ajax Session失效跳轉登錄頁面的方法
- Session過期后實現(xiàn)自動跳轉登錄頁面