JSP to resolve session expiration jump to the landing page and jump out of the IFRAME frame method _jsp Programming

Source: Internet
Author: User
You can set the redirect page with a filter when the session expires
Copy Code code 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);
}
}

But this can not not jump out of the framework such as IFRAME.
You can use JavaScript to solve
Add the following code to the page where you want to control the jump, such as the
Copy Code code as follows:

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

JS Refresh Frame Script statement
Copy Code code as follows:

//How to refresh the page containing the frame   
<script language=javascript>
& nbsp;  parent.location.reload ();
</script> 
//Child Windows Refresh parent window
<script language=javascript>
    Self.opener.location.reload ();
</script>
(or <a href= "javascript:opener.location.reload ()" > Refresh </a>  )
// How to refresh the page for another frame with   
<script language=javascript>
   parent. Another FrameID.location.reload ();
</script>
If you want to refresh when you close the window or refresh when you want to open it, call the following statement in <body>.
<body onload= "opener.location.reload ()" > Refresh when windows open
<body onunload= "opener.location.reload ()" > Refresh when closed
<script language= "JavaScript" >
window.opener.document.location.reload ()
</script>
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: 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.