php页面跳出框架,Jsp中解决session过期跳转到登陆页面并跳出iframe框架的方法

当Session过期时,通过Java过滤器实现重定向到登录页面,但无法直接跳出iframe。为解决此问题,可以在登录页面使用JavaScript进行刷新或关闭窗口操作,例如使用`parent.location.reload()`或`window.opener.document.location.reload()`来刷新父窗口或打开窗口。
摘要由CSDN通过智能技术生成

当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中的

与之间加入以下代码:

JS刷新框架的脚本语句//如何刷新包含该框架的页面用

parent.location.reload();

//子窗口刷新父窗口

self.opener.location.reload();

( 或 刷新 )

//如何刷新另一个框架的页面用

parent.另一FrameID.location.reload();

如果想关闭窗口时刷新或者想开窗时刷新的话,在

中调用以下语句即可。

window.opener.document.location.reload()

更多Jsp中解决session过期跳转到登陆页面并跳出iframe框架的方法相关文章请关注PHP中文网!

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值