Jsp to resolve the session expiration jump to the landing page and out of the iframe framework

  • 2020-06-23 01:41:08
  • OfStack

You can set the redirect page with a filter when session expires

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);
}
}

But you can't break out of iframe and so on.
You can do it with javaScript
On pages where you want to control the jump, such as login.jsp < head > with < /head > Add the following code between:

<script language= " JavaScript " > 
if (window != top) 
top.location.href = location.href; 
</script>

JS refreshes the script statements of the framework

// How to refresh the page containing the frame    
<script language=JavaScript>
   parent.location.reload();
</script>  
// Child window refreshes parent window 
<script language=JavaScript>
    self.opener.location.reload();
</script>
( or <a href="javascript:opener.location.reload()"> The refresh </a>   )
// How to refresh another 1 A frame of the page to use    
<script language=JavaScript>
   parent. On the other 1FrameID.location.reload();
</script>
 Refresh if you want to close the window or if you want to open the window <body> You can simply call the following statement. 
<body onload="opener.location.reload()">  Refresh when you open the window 
<body onUnload="opener.location.reload()">  Refresh on off 
<script language="javascript">
window.opener.document.location.reload()
</script>

Related articles: