Jsp solves the problem of jump to the login page when the session expires and jump out of the iframe framework

Source: Internet
Author: User

When the session expires, you can use a filter to set the redirection page.
Copy codeThe Code is as follows:
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 Copy codeThe Code is as follows:
<Script language = "JavaScript">
If (window! = Top)
Top. location. href = location. href;
</Script>

JS refresh framework script statement
Copy codeThe Code is as follows:
// How to refresh the page containing the framework
<Script language = JavaScript>
Parent. location. reload ();
</Script>
// Refresh the parent window in the Child Window
<Script language = JavaScript>
Self. opener. location. reload ();
</Script>
(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 ();
</Script>
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 ()
</Script>

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: info-contact@alibabacloud.com 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.