The final solution for clearing session after IE is directly disabled in JSP

Source: Internet
Author: User
Specific Practices: Step 1:All {
Document. write ('<IFRAME width = "100" Height = "100" src = "Rs. JSP "> </iframe> <object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = webbrowser width = 0> </Object> ');
Document. All. webbrowser. execwb (45, 1 );
}}</SCRIPT>
Step 2:Write <body onUnload = "removeonline ();"> </body> in <body> </body> of HTML. Note the case sensitivity: 1. If (event. clientx <0 & event. clienty <0) {} is used to determine whether IE is refreshed or closed. If it is a refresh event. clinetx and event. clienty must be greater than 0. Document. write ('<IFRAME width = "100" Height = "100" src = "Rs. JSP "> </iframe> <object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = webbrowser width = 0> </Object> ');
Document. all. webbrowser. execwb (); this is to create a control that comes with IE in IE. The control name is webbrowser. The function of the code here is to create an IFRAME on this page and set it to Rs in IFRAME. JSP file, Rs. the content of the JSP file is as follows: <% @ page Language = "Java" contenttype = "text/html; charset = gb2312"
Pageencoding = "gb2312" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> insert title here </title>
</Head>
<Body>
<% Session. invalidate (); %>
</Body>
</Html> then, after IFRAME loads Rs. jsp, it immediately calls document. All. webbrowser. execwb );

Force IE to close. There is usually a prompt box when IE is closed. You need to click "yes" or "no", so document. all. webbrowser. execwb (); the role of this statement is to force IE to close without displaying the prompt box, so the session is closed before IE is closed. invalidate () is triggered, session. when the invalidate is triggered, the sessioncounter that is already in the project is automatically called. the logout method in the Java class, so the logout event must be the sesssioncounter that is normally executed before IE is disabled. the Java content is as follows:
Import javax. servlet .*;
Import javax. servlet. http. *; import org. Apache. log4j. Logger;
Public class sessioncounter implements httpsessionlistener {Private Static int activesessions = 0;
Logger log = logger. getlogger (sessioncounter. Class. getname ());
Public void sessioncreated (httpsessionevent SE ){
Httpsession session = NULL;
Try {
Session = Se. getsession ();
Session. setmaxinactiveinterval (15*60 );
Log.info ("session time start now ");
} Catch (exception ex ){
System. Out. println ("session set error:" + ex );
Ex. printstacktrace ();
}
// System. Out. println (sysdateandtime. getsystemdatetime () + "session created ");
} Public void sessiondestroyed (httpsessionevent SE ){
// Some things that should be done in the destroy () event can include some of the enterprise processes that should be executed when you exit.
} // Public static int getactivesessions (){
// Return activesessions;
//}
} To deploy this sessioncounter. Java, you must add <listener> to Web. xml.
<Listener-class>
Com. ECC. util. sessioncounter
</Listener-class>
</Listener> other projects can also be set to ensure that the logout event is properly triggered when IE is disabled.
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.