当前位置: 编程技术>java/j2ee
Jsp中解决session过期跳转到登陆页面并跳出iframe框架的方法
来源: 互联网 发布时间:2014-10-19
本文导语: 当session过期后可以用过滤器来设置重定向页面 代码如下:public class ActionFilter extends HttpServlet implements Filter {private FilterConfig filterConfig;public void init(FilterConfig config) {this.filterConfig = config;}public void doFilter(ServletRequest servletRequest, Serv...
当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中的与之间加入以下代码:
if (window != top)
top.location.href = location.href;
JS刷新框架的脚本语句
//如何刷新包含该框架的页面用
parent.location.reload();
//子窗口刷新父窗口
self.opener.location.reload();
( 或 刷新 )
//如何刷新另一个框架的页面用
parent.另一FrameID.location.reload();
如果想关闭窗口时刷新或者想开窗时刷新的话,在中调用以下语句即可。
开窗时刷新
关闭时刷新
window.opener.document.location.reload()
代码如下:
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中的与之间加入以下代码:
代码如下:
if (window != top)
top.location.href = location.href;
JS刷新框架的脚本语句
代码如下:
//如何刷新包含该框架的页面用
parent.location.reload();
//子窗口刷新父窗口
self.opener.location.reload();
( 或 刷新 )
//如何刷新另一个框架的页面用
parent.另一FrameID.location.reload();
如果想关闭窗口时刷新或者想开窗时刷新的话,在中调用以下语句即可。
开窗时刷新
关闭时刷新
window.opener.document.location.reload()