Solve session expiration in Jsp jump to login page and jump out of iframe framework

Source: Internet
Author: User

Here we will introduce a website management backend three framework pages. When the session variable defined in jsp times out, the user will automatically exit the framework page upon clicking it and jump to the logon page, the following is an example.

When the session expires, you can use a filter to set the redirection page.

The Code is as follows: Copy code

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

However, you cannot jump out of frameworks such as iframe.

It can be solved using javaScript

Add the following code between the pages you want to control the redirection, such as

The Code is as follows: Copy code

<Script language = "JavaScript">
If (window! = Top)
Top. location. href = location. href;

JS refresh framework script statement

The Code is as follows: Copy code

// How to refresh the page containing the framework
<Script language = JavaScript>
Parent. location. reload ();

// Refresh the parent window in the Child Window
<Script language = JavaScript>
Self. opener. location. reload ();
(Or <a href = "javascript: opener. location. reload ()"> refresh </a>)

// How to refresh the page of another framework
<Script language = JavaScript>
Parent. Another FrameID. location. reload ();

If you want to refresh the window when closing the window or refresh the window when opening the window, you can call the following statement in <body>.

<Body onload = "opener. location. reload ()"> refresh when opening a window
<Body onUnload = "opener. location. reload ()"> refresh when disabled

<Script language = "javascript">
Zookeeper opener.doc ument. location. reload ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.