Jsp中解決session過(guò)期跳轉(zhuǎn)到登陸頁(yè)面并跳出iframe框架的方法
更新時(shí)間:2013年08月15日 17:44:31 作者:
這里我們是介紹一個(gè)網(wǎng)站管理后臺(tái)三個(gè)框架頁(yè)面當(dāng)我們的jsp定義的session變量超時(shí)時(shí)用戶點(diǎn)擊時(shí)自動(dòng)退出框架頁(yè)面并跳到登錄頁(yè)面去了,下面我來(lái)給大家演示一個(gè)實(shí)例
當(dāng)session過(guò)期后可以用過(guò)濾器來(lái)設(shè)置重定向頁(yè)面
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解決
在你想控制跳轉(zhuǎn)的頁(yè)面,比如login.jsp中的<head>與</head>之間加入以下代碼:
<script language=”JavaScript”>
if (window != top)
top.location.href = location.href;
</script>
JS刷新框架的腳本語(yǔ)句
//如何刷新包含該框架的頁(yè)面用
<script language=JavaScript>
parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )
//如何刷新另一個(gè)框架的頁(yè)面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>
如果想關(guān)閉窗口時(shí)刷新或者想開(kāi)窗時(shí)刷新的話,在<body>中調(diào)用以下語(yǔ)句即可。
<body onload="opener.location.reload()"> 開(kāi)窗時(shí)刷新
<body onUnload="opener.location.reload()"> 關(guān)閉時(shí)刷新
<script language="javascript">
window.opener.document.location.reload()
</script>
復(fù)制代碼 代碼如下:
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解決
在你想控制跳轉(zhuǎn)的頁(yè)面,比如login.jsp中的<head>與</head>之間加入以下代碼:
復(fù)制代碼 代碼如下:
<script language=”JavaScript”>
if (window != top)
top.location.href = location.href;
</script>
JS刷新框架的腳本語(yǔ)句
復(fù)制代碼 代碼如下:
//如何刷新包含該框架的頁(yè)面用
<script language=JavaScript>
parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )
//如何刷新另一個(gè)框架的頁(yè)面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>
如果想關(guān)閉窗口時(shí)刷新或者想開(kāi)窗時(shí)刷新的話,在<body>中調(diào)用以下語(yǔ)句即可。
<body onload="opener.location.reload()"> 開(kāi)窗時(shí)刷新
<body onUnload="opener.location.reload()"> 關(guān)閉時(shí)刷新
<script language="javascript">
window.opener.document.location.reload()
</script>
您可能感興趣的文章:
- Java Web實(shí)現(xiàn)session過(guò)期后自動(dòng)跳轉(zhuǎn)到登陸頁(yè)功能【基于過(guò)濾器】
- 詳解springmvc控制登錄用戶session失效后跳轉(zhuǎn)登錄頁(yè)面
- php頁(yè)面跳轉(zhuǎn)session cookie丟失導(dǎo)致不能登錄等問(wèn)題的解決方法
- webix+springmvc session超時(shí)跳轉(zhuǎn)登錄頁(yè)面
- jQuery ajax全局函數(shù)處理session過(guò)期后的ajax跳轉(zhuǎn)問(wèn)題
- ajax提交session超時(shí)跳轉(zhuǎn)頁(yè)面使用全局的方法來(lái)處理
- Session過(guò)期后自動(dòng)跳轉(zhuǎn)到登錄頁(yè)面的實(shí)例代碼
- Ajax Session失效跳轉(zhuǎn)登錄頁(yè)面的方法
- Session過(guò)期后實(shí)現(xiàn)自動(dòng)跳轉(zhuǎn)登錄頁(yè)面
相關(guān)文章
jsp和servlet操作mysql中文亂碼問(wèn)題的解決辦法
自己做測(cè)試的時(shí)候用到j(luò)sp/servlet 向mysql中寫(xiě)數(shù)據(jù),但是中文總是亂碼,今早糾結(jié)了半天才搞定,分享給大家我的解決辦法2014-04-04jsp從數(shù)據(jù)庫(kù)獲取數(shù)據(jù)填充下拉框?qū)崿F(xiàn)二級(jí)聯(lián)動(dòng)菜單的方法
這篇文章主要介紹了jsp從數(shù)據(jù)庫(kù)獲取數(shù)據(jù)填充下拉框?qū)崿F(xiàn)二級(jí)聯(lián)動(dòng)菜單的方法,涉及jsp數(shù)據(jù)庫(kù)的操作及聯(lián)動(dòng)菜單的構(gòu)造技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10jsp導(dǎo)出身份證到excel時(shí)候格式不對(duì)但以X結(jié)尾的卻可以
excel導(dǎo)出身份證的時(shí)候顯示有的對(duì)有的不對(duì),身份證以X結(jié)尾的可以,其它都顯示不正確,關(guān)于這個(gè)問(wèn)題的解決方法如下,需要的朋友可以參考下2014-10-10